@prover-coder-ai/context-doc 1.0.9 → 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.
@@ -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 (locator.normalizedCwd.startsWith(normalized) ||
40
- normalized.startsWith(locator.normalizedCwd));
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
+ };
@@ -96,6 +96,17 @@ const selectRelevantFiles = (files, locator) => Effect.reduce(files, [], (acc, f
96
96
  }
97
97
  return acc;
98
98
  })));
99
+ const resolveLocator = (options) => pipe(readRepositoryUrl(options.cwd, options.repositoryUrlOverride), Effect.map((repositoryUrl) => buildProjectLocator(repositoryUrl, options.cwd)), Effect.catchAll(() => Effect.gen(function* (__) {
100
+ yield* __(Console.log("Codex repository url missing; falling back to cwd-only match"));
101
+ return buildProjectLocator(options.cwd, options.cwd);
102
+ })));
103
+ const copyCodexFiles = (sourceDir, destinationDir, locator) => Effect.gen(function* (_) {
104
+ yield* _(ensureDirectory(destinationDir));
105
+ const allJsonlFiles = yield* _(collectJsonlFiles(sourceDir));
106
+ const relevantFiles = yield* _(selectRelevantFiles(allJsonlFiles, locator));
107
+ yield* _(Effect.forEach(relevantFiles, (filePath) => copyRelevantFile(sourceDir, destinationDir, filePath)));
108
+ yield* _(Console.log(`Codex: copied ${relevantFiles.length} files from ${sourceDir} to ${destinationDir}`));
109
+ });
99
110
  // CHANGE: Extract Codex dialog sync into dedicated module for clarity.
100
111
  // WHY: Separate Codex-specific shell effects from other sync flows.
101
112
  // QUOTE(ТЗ): "вынеси в отдельный файл"
@@ -107,17 +118,12 @@ const selectRelevantFiles = (files, locator) => Effect.reduce(files, [], (acc, f
107
118
  // INVARIANT: ∀f ∈ copiedFiles: linesMatchProject(f, locator)
108
119
  // COMPLEXITY: O(n) time / O(n) space, n = |files|
109
120
  export const syncCodex = (options) => Effect.gen(function* (_) {
110
- const repositoryUrl = yield* _(readRepositoryUrl(options.cwd, options.repositoryUrlOverride));
121
+ const locator = yield* _(resolveLocator(options));
111
122
  const sourceDir = yield* _(resolveSourceDir(options.cwd, options.sourceDir, options.metaRoot));
112
123
  const destinationDir = options.destinationDir ?? path.join(options.cwd, ".knowledge", ".codex");
113
124
  if (path.resolve(sourceDir) === path.resolve(destinationDir)) {
114
125
  yield* _(Console.log("Codex source equals destination; skipping copy to avoid duplicates"));
115
126
  return;
116
127
  }
117
- yield* _(ensureDirectory(destinationDir));
118
- const locator = buildProjectLocator(repositoryUrl, options.cwd);
119
- const allJsonlFiles = yield* _(collectJsonlFiles(sourceDir));
120
- const relevantFiles = yield* _(selectRelevantFiles(allJsonlFiles, locator));
121
- yield* _(Effect.forEach(relevantFiles, (filePath) => copyRelevantFile(sourceDir, destinationDir, filePath)));
122
- yield* _(Console.log(`Codex: copied ${relevantFiles.length} files from ${sourceDir} to ${destinationDir}`));
128
+ yield* _(copyCodexFiles(sourceDir, destinationDir, locator));
123
129
  }).pipe(Effect.catchAll((error) => Console.log(`Codex source not found; skipped syncing Codex dialog files (${error.reason})`)));
@@ -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 { Console, Effect, pipe } from "effect";
6
- import { ensureDirectory, syncError } from "./syncShared.js";
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) => pipe(resolveQwenSourceDir(options.cwd, options.qwenSourceDir, options.metaRoot), Effect.flatMap((qwenSource) => Effect.gen(function* (_) {
57
- const destination = path.join(options.cwd, ".knowledge", ".qwen");
58
- if (path.resolve(qwenSource) === path.resolve(destination)) {
59
- yield* _(Console.log("Qwen source equals destination; skipping copy to avoid duplicates"));
60
- return;
61
- }
62
- yield* _(ensureDirectory(destination));
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];
@@ -1,5 +1,7 @@
1
1
  import fs from "node:fs";
2
- import { Effect } from "effect";
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.9",
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 build && npm run lint && npm version patch && npm publish --access public"
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"
@@ -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.startsWith(normalized) ||
120
- normalized.startsWith(locator.normalizedCwd)
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
+ };
@@ -155,6 +155,47 @@ const selectRelevantFiles = (
155
155
  ),
156
156
  );
157
157
 
158
+ const resolveLocator = (
159
+ options: SyncOptions,
160
+ ): Effect.Effect<ProjectLocator, SyncError> =>
161
+ pipe(
162
+ readRepositoryUrl(options.cwd, options.repositoryUrlOverride),
163
+ Effect.map((repositoryUrl) =>
164
+ buildProjectLocator(repositoryUrl, options.cwd),
165
+ ),
166
+ Effect.catchAll(() =>
167
+ Effect.gen(function* (__) {
168
+ yield* __(
169
+ Console.log(
170
+ "Codex repository url missing; falling back to cwd-only match",
171
+ ),
172
+ );
173
+ return buildProjectLocator(options.cwd, options.cwd);
174
+ }),
175
+ ),
176
+ );
177
+
178
+ const copyCodexFiles = (
179
+ sourceDir: string,
180
+ destinationDir: string,
181
+ locator: ProjectLocator,
182
+ ): Effect.Effect<void, SyncError> =>
183
+ Effect.gen(function* (_) {
184
+ yield* _(ensureDirectory(destinationDir));
185
+ const allJsonlFiles = yield* _(collectJsonlFiles(sourceDir));
186
+ const relevantFiles = yield* _(selectRelevantFiles(allJsonlFiles, locator));
187
+ yield* _(
188
+ Effect.forEach(relevantFiles, (filePath) =>
189
+ copyRelevantFile(sourceDir, destinationDir, filePath),
190
+ ),
191
+ );
192
+ yield* _(
193
+ Console.log(
194
+ `Codex: copied ${relevantFiles.length} files from ${sourceDir} to ${destinationDir}`,
195
+ ),
196
+ );
197
+ });
198
+
158
199
  // CHANGE: Extract Codex dialog sync into dedicated module for clarity.
159
200
  // WHY: Separate Codex-specific shell effects from other sync flows.
160
201
  // QUOTE(ТЗ): "вынеси в отдельный файл"
@@ -169,9 +210,7 @@ export const syncCodex = (
169
210
  options: SyncOptions,
170
211
  ): Effect.Effect<void, SyncError> =>
171
212
  Effect.gen(function* (_) {
172
- const repositoryUrl = yield* _(
173
- readRepositoryUrl(options.cwd, options.repositoryUrlOverride),
174
- );
213
+ const locator = yield* _(resolveLocator(options));
175
214
  const sourceDir = yield* _(
176
215
  resolveSourceDir(options.cwd, options.sourceDir, options.metaRoot),
177
216
  );
@@ -187,23 +226,7 @@ export const syncCodex = (
187
226
  return;
188
227
  }
189
228
 
190
- yield* _(ensureDirectory(destinationDir));
191
-
192
- const locator = buildProjectLocator(repositoryUrl, options.cwd);
193
- const allJsonlFiles = yield* _(collectJsonlFiles(sourceDir));
194
- const relevantFiles = yield* _(selectRelevantFiles(allJsonlFiles, locator));
195
-
196
- yield* _(
197
- Effect.forEach(relevantFiles, (filePath) =>
198
- copyRelevantFile(sourceDir, destinationDir, filePath),
199
- ),
200
- );
201
-
202
- yield* _(
203
- Console.log(
204
- `Codex: copied ${relevantFiles.length} files from ${sourceDir} to ${destinationDir}`,
205
- ),
206
- );
229
+ yield* _(copyCodexFiles(sourceDir, destinationDir, locator));
207
230
  }).pipe(
208
231
  Effect.catchAll((error) =>
209
232
  Console.log(
@@ -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 { Console, Effect, pipe } from "effect";
6
- import { ensureDirectory, syncError } from "./syncShared.js";
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
- yield* _(ensureDirectory(destination));
101
- const qwenRoot = path.dirname(path.dirname(qwenSource));
102
- const copiedCount = yield* _(
103
- copyDirectoryJsonOnly(qwenSource, destination),
104
- );
105
- yield* _(
106
- Console.log(
107
- `Qwen: copied ${copiedCount} files from ${qwenRoot} to ${destination}`,
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++) {
@@ -1,6 +1,8 @@
1
1
  import fs from "node:fs";
2
- import { Effect } from "effect";
3
- import type { SyncError } from "./syncTypes.js";
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
+ });
@@ -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
  }