@prover-coder-ai/context-doc 1.0.10 → 1.0.11
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/dist/core/knowledge.js +5 -2
- package/dist/shell/claudeSync.js +23 -0
- package/dist/shell/qwenSync.js +9 -34
- package/dist/shell/syncKnowledge.js +3 -0
- package/dist/shell/syncShared.js +37 -1
- package/package.json +3 -2
- package/src/core/knowledge.ts +7 -4
- package/src/shell/claudeSync.ts +55 -0
- package/src/shell/qwenSync.ts +16 -60
- package/src/shell/syncKnowledge.ts +3 -0
- package/src/shell/syncShared.ts +76 -2
- package/src/shell/syncTypes.ts +16 -0
package/dist/core/knowledge.js
CHANGED
|
@@ -33,11 +33,14 @@ const safeParseJson = (line) => {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
const metadataMatches = (metadata, locator) => {
|
|
36
|
+
const fallbackCwdOnly = locator.normalizedRepositoryUrl === locator.normalizedCwd;
|
|
36
37
|
const repoMatches = Option.exists(metadata.repositoryUrl, (repositoryUrl) => normalizeRepositoryUrl(repositoryUrl) === locator.normalizedRepositoryUrl);
|
|
37
38
|
const cwdMatches = Option.exists(metadata.cwd, (cwdValue) => {
|
|
38
39
|
const normalized = normalizeCwd(cwdValue);
|
|
39
|
-
return
|
|
40
|
-
normalized
|
|
40
|
+
return fallbackCwdOnly
|
|
41
|
+
? normalized === locator.normalizedCwd
|
|
42
|
+
: locator.normalizedCwd.startsWith(normalized) ||
|
|
43
|
+
normalized.startsWith(locator.normalizedCwd);
|
|
41
44
|
});
|
|
42
45
|
return repoMatches || cwdMatches;
|
|
43
46
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as NodeFs from "node:fs";
|
|
2
|
+
import * as NodeOs from "node:os";
|
|
3
|
+
import * as NodePath from "node:path";
|
|
4
|
+
import { Effect, pipe } from "effect";
|
|
5
|
+
import { copyFilteredFiles, runSyncSource, syncError } from "./syncShared.js";
|
|
6
|
+
const slugFromCwd = (cwd) => `-${cwd.replace(/^\/+/, "").replace(/\//g, "-")}`;
|
|
7
|
+
const resolveClaudeProjectDir = (cwd, overrideProjectsRoot) => pipe(Effect.sync(() => {
|
|
8
|
+
const slug = slugFromCwd(cwd);
|
|
9
|
+
const base = overrideProjectsRoot ??
|
|
10
|
+
NodePath.join(NodeOs.homedir(), ".claude", "projects");
|
|
11
|
+
const candidate = NodePath.join(base, slug);
|
|
12
|
+
return NodeFs.existsSync(candidate) ? candidate : undefined;
|
|
13
|
+
}), Effect.flatMap((found) => found === undefined
|
|
14
|
+
? Effect.fail(syncError(".claude", "Claude project directory is missing"))
|
|
15
|
+
: Effect.succeed(found)));
|
|
16
|
+
const copyClaudeJsonl = (sourceDir, destinationDir) => copyFilteredFiles(sourceDir, destinationDir, (entry, fullPath) => entry.isFile() && fullPath.endsWith(".jsonl"), "Cannot traverse Claude project");
|
|
17
|
+
export const syncClaude = (options) => runSyncSource(claudeSource, options);
|
|
18
|
+
const claudeSource = {
|
|
19
|
+
name: "Claude",
|
|
20
|
+
destSubdir: ".claude",
|
|
21
|
+
resolveSource: (options) => resolveClaudeProjectDir(options.cwd, options.claudeProjectsRoot),
|
|
22
|
+
copy: (sourceDir, destinationDir) => copyClaudeJsonl(sourceDir, destinationDir),
|
|
23
|
+
};
|
package/dist/shell/qwenSync.js
CHANGED
|
@@ -2,29 +2,8 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
const copyDirectoryJsonOnly = (sourceRoot, destinationRoot) => Effect.try({
|
|
8
|
-
try: () => {
|
|
9
|
-
let copied = 0;
|
|
10
|
-
fs.cpSync(sourceRoot, destinationRoot, {
|
|
11
|
-
recursive: true,
|
|
12
|
-
filter: (src) => {
|
|
13
|
-
const stat = fs.statSync(src);
|
|
14
|
-
if (stat.isDirectory()) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
if (src.endsWith(".json")) {
|
|
18
|
-
copied += 1;
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
return copied;
|
|
25
|
-
},
|
|
26
|
-
catch: () => syncError(sourceRoot, "Cannot traverse Qwen directory"),
|
|
27
|
-
});
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { copyFilteredFiles, runSyncSource, syncError } from "./syncShared.js";
|
|
28
7
|
const qwenHashFromPath = (projectPath) => createHash("sha256").update(projectPath).digest("hex");
|
|
29
8
|
const resolveQwenSourceDir = (cwd, override, metaRoot) => Effect.gen(function* (_) {
|
|
30
9
|
const hash = qwenHashFromPath(cwd);
|
|
@@ -53,14 +32,10 @@ const resolveQwenSourceDir = (cwd, override, metaRoot) => Effect.gen(function* (
|
|
|
53
32
|
}
|
|
54
33
|
return found;
|
|
55
34
|
});
|
|
56
|
-
export const syncQwen = (options) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const qwenRoot = path.dirname(path.dirname(qwenSource));
|
|
64
|
-
const copiedCount = yield* _(copyDirectoryJsonOnly(qwenSource, destination));
|
|
65
|
-
yield* _(Console.log(`Qwen: copied ${copiedCount} files from ${qwenRoot} to ${destination}`));
|
|
66
|
-
})), Effect.catchAll((error) => Console.log(`Qwen source not found; skipped syncing Qwen dialog files (${error.reason})`)));
|
|
35
|
+
export const syncQwen = (options) => runSyncSource(qwenSource, options);
|
|
36
|
+
const qwenSource = {
|
|
37
|
+
name: "Qwen",
|
|
38
|
+
destSubdir: ".qwen",
|
|
39
|
+
resolveSource: (options) => resolveQwenSourceDir(options.cwd, options.qwenSourceDir, options.metaRoot),
|
|
40
|
+
copy: (sourceDir, destinationDir) => copyFilteredFiles(sourceDir, destinationDir, (entry, fullPath) => entry.isFile() && fullPath.endsWith(".json"), "Cannot traverse Qwen directory"),
|
|
41
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
+
import { syncClaude } from "./claudeSync.js";
|
|
3
4
|
import { syncCodex } from "./codexSync.js";
|
|
4
5
|
import { syncQwen } from "./qwenSync.js";
|
|
5
6
|
// PURPOSE: Sync project-scoped dialogs (Codex + Qwen) into .knowledge storage.
|
|
6
7
|
export const buildSyncProgram = (options) => Effect.gen(function* (_) {
|
|
8
|
+
yield* _(syncClaude(options));
|
|
7
9
|
yield* _(syncCodex(options));
|
|
8
10
|
yield* _(syncQwen(options));
|
|
9
11
|
});
|
|
@@ -19,6 +21,7 @@ export const parseArgs = () => {
|
|
|
19
21
|
"--project-name": "repositoryUrlOverride",
|
|
20
22
|
"--meta-root": "metaRoot",
|
|
21
23
|
"--qwen-source": "qwenSourceDir",
|
|
24
|
+
"--claude-projects": "claudeProjectsRoot",
|
|
22
25
|
};
|
|
23
26
|
for (let i = 0; i < argv.length; i++) {
|
|
24
27
|
const arg = argv[i];
|
package/dist/shell/syncShared.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Console, Effect } from "effect";
|
|
4
|
+
import { pipe } from "effect/Function";
|
|
3
5
|
export const syncError = (pathValue, reason) => ({
|
|
4
6
|
_tag: "SyncError",
|
|
5
7
|
path: pathValue,
|
|
@@ -11,3 +13,37 @@ export const ensureDirectory = (directory) => Effect.try({
|
|
|
11
13
|
},
|
|
12
14
|
catch: () => syncError(directory, "Cannot create destination directory structure"),
|
|
13
15
|
});
|
|
16
|
+
export const runSyncSource = (source, options) => pipe(Effect.gen(function* (_) {
|
|
17
|
+
const resolvedSource = yield* _(source.resolveSource(options));
|
|
18
|
+
const destination = path.join(options.cwd, ".knowledge", source.destSubdir);
|
|
19
|
+
if (path.resolve(resolvedSource) === path.resolve(destination)) {
|
|
20
|
+
yield* _(Console.log(`${source.name}: source equals destination; skipping copy to avoid duplicates`));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
yield* _(ensureDirectory(destination));
|
|
24
|
+
const copied = yield* _(source.copy(resolvedSource, destination, options));
|
|
25
|
+
yield* _(Console.log(`${source.name}: copied ${copied} files from ${resolvedSource} to ${destination}`));
|
|
26
|
+
}), Effect.catchAll((error) => Console.log(`${source.name}: source not found; skipped syncing (${error.reason})`)));
|
|
27
|
+
export const copyFilteredFiles = (sourceRoot, destinationRoot, isRelevant, errorReason) => Effect.try({
|
|
28
|
+
try: () => {
|
|
29
|
+
let copied = 0;
|
|
30
|
+
const walk = (current) => {
|
|
31
|
+
const entries = fs.readdirSync(current, { withFileTypes: true });
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
const full = path.join(current, entry.name);
|
|
34
|
+
if (entry.isDirectory()) {
|
|
35
|
+
walk(full);
|
|
36
|
+
}
|
|
37
|
+
else if (isRelevant(entry, full)) {
|
|
38
|
+
const target = path.join(destinationRoot, path.relative(sourceRoot, full));
|
|
39
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
40
|
+
fs.copyFileSync(full, target);
|
|
41
|
+
copied += 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
walk(sourceRoot);
|
|
46
|
+
return copied;
|
|
47
|
+
},
|
|
48
|
+
catch: () => syncError(sourceRoot, errorReason),
|
|
49
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prover-coder-ai/context-doc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
"build": "tsc -p tsconfig.build.json",
|
|
9
9
|
"lint": "npx --no-install @ton-ai-core/vibecode-linter src/",
|
|
10
10
|
"test": "npx --no-install @ton-ai-core/vibecode-linter tests/ && vitest run --passWithNoTests",
|
|
11
|
+
"prepare": "git config core.hooksPath .githooks && chmod +x .githooks/pre-commit",
|
|
11
12
|
"sync:knowledge": "npm run build && PKG=prover-coder-ai-context-doc-$(node -p \"require('./package.json').version\").tgz && rm -f \"$PKG\" && npm pack >/dev/null && npx -y -p \"./$PKG\" context-doc",
|
|
12
|
-
"release": "npm run
|
|
13
|
+
"release": "npm run lint && npm run build && npm version patch && npm publish --access public"
|
|
13
14
|
},
|
|
14
15
|
"bin": {
|
|
15
16
|
"context-doc": "dist/shell/cli.js"
|
package/src/core/knowledge.ts
CHANGED
|
@@ -107,6 +107,9 @@ const metadataMatches = (
|
|
|
107
107
|
metadata: RecordMetadata,
|
|
108
108
|
locator: ProjectLocator,
|
|
109
109
|
): boolean => {
|
|
110
|
+
const fallbackCwdOnly =
|
|
111
|
+
locator.normalizedRepositoryUrl === locator.normalizedCwd;
|
|
112
|
+
|
|
110
113
|
const repoMatches = Option.exists(
|
|
111
114
|
metadata.repositoryUrl,
|
|
112
115
|
(repositoryUrl) =>
|
|
@@ -115,10 +118,10 @@ const metadataMatches = (
|
|
|
115
118
|
|
|
116
119
|
const cwdMatches = Option.exists(metadata.cwd, (cwdValue) => {
|
|
117
120
|
const normalized = normalizeCwd(cwdValue);
|
|
118
|
-
return
|
|
119
|
-
locator.normalizedCwd
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
return fallbackCwdOnly
|
|
122
|
+
? normalized === locator.normalizedCwd
|
|
123
|
+
: locator.normalizedCwd.startsWith(normalized) ||
|
|
124
|
+
normalized.startsWith(locator.normalizedCwd);
|
|
122
125
|
});
|
|
123
126
|
|
|
124
127
|
return repoMatches || cwdMatches;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as NodeFs from "node:fs";
|
|
2
|
+
import * as NodeOs from "node:os";
|
|
3
|
+
import * as NodePath from "node:path";
|
|
4
|
+
import { Effect, pipe } from "effect";
|
|
5
|
+
import { copyFilteredFiles, runSyncSource, syncError } from "./syncShared.js";
|
|
6
|
+
import type { SyncError, SyncOptions, SyncSource } from "./syncTypes.js";
|
|
7
|
+
|
|
8
|
+
const slugFromCwd = (cwd: string): string =>
|
|
9
|
+
`-${cwd.replace(/^\/+/, "").replace(/\//g, "-")}`;
|
|
10
|
+
|
|
11
|
+
const resolveClaudeProjectDir = (
|
|
12
|
+
cwd: string,
|
|
13
|
+
overrideProjectsRoot?: string,
|
|
14
|
+
): Effect.Effect<string, SyncError> =>
|
|
15
|
+
pipe(
|
|
16
|
+
Effect.sync(() => {
|
|
17
|
+
const slug = slugFromCwd(cwd);
|
|
18
|
+
const base =
|
|
19
|
+
overrideProjectsRoot ??
|
|
20
|
+
NodePath.join(NodeOs.homedir(), ".claude", "projects");
|
|
21
|
+
const candidate = NodePath.join(base, slug);
|
|
22
|
+
return NodeFs.existsSync(candidate) ? candidate : undefined;
|
|
23
|
+
}),
|
|
24
|
+
Effect.flatMap((found) =>
|
|
25
|
+
found === undefined
|
|
26
|
+
? Effect.fail(
|
|
27
|
+
syncError(".claude", "Claude project directory is missing"),
|
|
28
|
+
)
|
|
29
|
+
: Effect.succeed(found),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const copyClaudeJsonl = (
|
|
34
|
+
sourceDir: string,
|
|
35
|
+
destinationDir: string,
|
|
36
|
+
): Effect.Effect<number, SyncError> =>
|
|
37
|
+
copyFilteredFiles(
|
|
38
|
+
sourceDir,
|
|
39
|
+
destinationDir,
|
|
40
|
+
(entry, fullPath) => entry.isFile() && fullPath.endsWith(".jsonl"),
|
|
41
|
+
"Cannot traverse Claude project",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const syncClaude = (
|
|
45
|
+
options: SyncOptions,
|
|
46
|
+
): Effect.Effect<void, SyncError> => runSyncSource(claudeSource, options);
|
|
47
|
+
|
|
48
|
+
const claudeSource: SyncSource = {
|
|
49
|
+
name: "Claude",
|
|
50
|
+
destSubdir: ".claude",
|
|
51
|
+
resolveSource: (options) =>
|
|
52
|
+
resolveClaudeProjectDir(options.cwd, options.claudeProjectsRoot),
|
|
53
|
+
copy: (sourceDir, destinationDir) =>
|
|
54
|
+
copyClaudeJsonl(sourceDir, destinationDir),
|
|
55
|
+
};
|
package/src/shell/qwenSync.ts
CHANGED
|
@@ -2,35 +2,9 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { SyncError, SyncOptions } from "./syncTypes.js";
|
|
8
|
-
|
|
9
|
-
const copyDirectoryJsonOnly = (
|
|
10
|
-
sourceRoot: string,
|
|
11
|
-
destinationRoot: string,
|
|
12
|
-
): Effect.Effect<number, SyncError> =>
|
|
13
|
-
Effect.try({
|
|
14
|
-
try: () => {
|
|
15
|
-
let copied = 0;
|
|
16
|
-
fs.cpSync(sourceRoot, destinationRoot, {
|
|
17
|
-
recursive: true,
|
|
18
|
-
filter: (src) => {
|
|
19
|
-
const stat = fs.statSync(src);
|
|
20
|
-
if (stat.isDirectory()) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
if (src.endsWith(".json")) {
|
|
24
|
-
copied += 1;
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
return copied;
|
|
31
|
-
},
|
|
32
|
-
catch: () => syncError(sourceRoot, "Cannot traverse Qwen directory"),
|
|
33
|
-
});
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { copyFilteredFiles, runSyncSource, syncError } from "./syncShared.js";
|
|
7
|
+
import type { SyncError, SyncOptions, SyncSource } from "./syncTypes.js";
|
|
34
8
|
|
|
35
9
|
const qwenHashFromPath = (projectPath: string): string =>
|
|
36
10
|
createHash("sha256").update(projectPath).digest("hex");
|
|
@@ -82,36 +56,18 @@ const resolveQwenSourceDir = (
|
|
|
82
56
|
|
|
83
57
|
export const syncQwen = (
|
|
84
58
|
options: SyncOptions,
|
|
85
|
-
): Effect.Effect<void, SyncError> =>
|
|
86
|
-
pipe(
|
|
87
|
-
resolveQwenSourceDir(options.cwd, options.qwenSourceDir, options.metaRoot),
|
|
88
|
-
Effect.flatMap((qwenSource) =>
|
|
89
|
-
Effect.gen(function* (_) {
|
|
90
|
-
const destination = path.join(options.cwd, ".knowledge", ".qwen");
|
|
91
|
-
if (path.resolve(qwenSource) === path.resolve(destination)) {
|
|
92
|
-
yield* _(
|
|
93
|
-
Console.log(
|
|
94
|
-
"Qwen source equals destination; skipping copy to avoid duplicates",
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
59
|
+
): Effect.Effect<void, SyncError> => runSyncSource(qwenSource, options);
|
|
99
60
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
),
|
|
112
|
-
Effect.catchAll((error) =>
|
|
113
|
-
Console.log(
|
|
114
|
-
`Qwen source not found; skipped syncing Qwen dialog files (${error.reason})`,
|
|
115
|
-
),
|
|
61
|
+
const qwenSource: SyncSource = {
|
|
62
|
+
name: "Qwen",
|
|
63
|
+
destSubdir: ".qwen",
|
|
64
|
+
resolveSource: (options) =>
|
|
65
|
+
resolveQwenSourceDir(options.cwd, options.qwenSourceDir, options.metaRoot),
|
|
66
|
+
copy: (sourceDir, destinationDir) =>
|
|
67
|
+
copyFilteredFiles(
|
|
68
|
+
sourceDir,
|
|
69
|
+
destinationDir,
|
|
70
|
+
(entry, fullPath) => entry.isFile() && fullPath.endsWith(".json"),
|
|
71
|
+
"Cannot traverse Qwen directory",
|
|
116
72
|
),
|
|
117
|
-
|
|
73
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
+
import { syncClaude } from "./claudeSync.js";
|
|
3
4
|
import { syncCodex } from "./codexSync.js";
|
|
4
5
|
import { syncQwen } from "./qwenSync.js";
|
|
5
6
|
import type { SyncError, SyncOptions } from "./syncTypes.js";
|
|
@@ -9,6 +10,7 @@ export const buildSyncProgram = (
|
|
|
9
10
|
options: SyncOptions,
|
|
10
11
|
): Effect.Effect<void, SyncError> =>
|
|
11
12
|
Effect.gen(function* (_) {
|
|
13
|
+
yield* _(syncClaude(options));
|
|
12
14
|
yield* _(syncCodex(options));
|
|
13
15
|
yield* _(syncQwen(options));
|
|
14
16
|
});
|
|
@@ -26,6 +28,7 @@ export const parseArgs = (): SyncOptions => {
|
|
|
26
28
|
"--project-name": "repositoryUrlOverride",
|
|
27
29
|
"--meta-root": "metaRoot",
|
|
28
30
|
"--qwen-source": "qwenSourceDir",
|
|
31
|
+
"--claude-projects": "claudeProjectsRoot",
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
for (let i = 0; i < argv.length; i++) {
|
package/src/shell/syncShared.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Console, Effect } from "effect";
|
|
4
|
+
import { pipe } from "effect/Function";
|
|
5
|
+
import type { SyncError, SyncOptions, SyncSource } from "./syncTypes.js";
|
|
4
6
|
|
|
5
7
|
export const syncError = (pathValue: string, reason: string): SyncError => ({
|
|
6
8
|
_tag: "SyncError",
|
|
@@ -18,3 +20,75 @@ export const ensureDirectory = (
|
|
|
18
20
|
catch: () =>
|
|
19
21
|
syncError(directory, "Cannot create destination directory structure"),
|
|
20
22
|
});
|
|
23
|
+
|
|
24
|
+
export const runSyncSource = (
|
|
25
|
+
source: SyncSource,
|
|
26
|
+
options: SyncOptions,
|
|
27
|
+
): Effect.Effect<void, SyncError> =>
|
|
28
|
+
pipe(
|
|
29
|
+
Effect.gen(function* (_) {
|
|
30
|
+
const resolvedSource = yield* _(source.resolveSource(options));
|
|
31
|
+
const destination = path.join(
|
|
32
|
+
options.cwd,
|
|
33
|
+
".knowledge",
|
|
34
|
+
source.destSubdir,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (path.resolve(resolvedSource) === path.resolve(destination)) {
|
|
38
|
+
yield* _(
|
|
39
|
+
Console.log(
|
|
40
|
+
`${source.name}: source equals destination; skipping copy to avoid duplicates`,
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
yield* _(ensureDirectory(destination));
|
|
47
|
+
const copied = yield* _(
|
|
48
|
+
source.copy(resolvedSource, destination, options),
|
|
49
|
+
);
|
|
50
|
+
yield* _(
|
|
51
|
+
Console.log(
|
|
52
|
+
`${source.name}: copied ${copied} files from ${resolvedSource} to ${destination}`,
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
}),
|
|
56
|
+
Effect.catchAll((error: SyncError) =>
|
|
57
|
+
Console.log(
|
|
58
|
+
`${source.name}: source not found; skipped syncing (${error.reason})`,
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const copyFilteredFiles = (
|
|
64
|
+
sourceRoot: string,
|
|
65
|
+
destinationRoot: string,
|
|
66
|
+
isRelevant: (entry: fs.Dirent, fullPath: string) => boolean,
|
|
67
|
+
errorReason: string,
|
|
68
|
+
): Effect.Effect<number, SyncError> =>
|
|
69
|
+
Effect.try({
|
|
70
|
+
try: () => {
|
|
71
|
+
let copied = 0;
|
|
72
|
+
const walk = (current: string): void => {
|
|
73
|
+
const entries = fs.readdirSync(current, { withFileTypes: true });
|
|
74
|
+
for (const entry of entries) {
|
|
75
|
+
const full = path.join(current, entry.name);
|
|
76
|
+
if (entry.isDirectory()) {
|
|
77
|
+
walk(full);
|
|
78
|
+
} else if (isRelevant(entry, full)) {
|
|
79
|
+
const target = path.join(
|
|
80
|
+
destinationRoot,
|
|
81
|
+
path.relative(sourceRoot, full),
|
|
82
|
+
);
|
|
83
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
84
|
+
fs.copyFileSync(full, target);
|
|
85
|
+
copied += 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
walk(sourceRoot);
|
|
91
|
+
return copied;
|
|
92
|
+
},
|
|
93
|
+
catch: () => syncError(sourceRoot, errorReason),
|
|
94
|
+
});
|
package/src/shell/syncTypes.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type * as Fx from "effect";
|
|
2
|
+
|
|
1
3
|
export interface SyncError {
|
|
2
4
|
readonly _tag: "SyncError";
|
|
3
5
|
readonly path: string;
|
|
@@ -11,4 +13,18 @@ export interface SyncOptions {
|
|
|
11
13
|
readonly repositoryUrlOverride?: string;
|
|
12
14
|
readonly metaRoot?: string;
|
|
13
15
|
readonly qwenSourceDir?: string;
|
|
16
|
+
readonly claudeProjectsRoot?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type SyncEffect<A> = Fx.Effect.Effect<A, SyncError>;
|
|
20
|
+
|
|
21
|
+
export interface SyncSource {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly destSubdir: ".codex" | ".qwen" | ".claude";
|
|
24
|
+
readonly resolveSource: (options: SyncOptions) => SyncEffect<string>;
|
|
25
|
+
readonly copy: (
|
|
26
|
+
sourceDir: string,
|
|
27
|
+
destinationDir: string,
|
|
28
|
+
options: SyncOptions,
|
|
29
|
+
) => SyncEffect<number>;
|
|
14
30
|
}
|