dsh-cuigengji-plugin 0.4.2 → 0.4.4

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.
Files changed (67) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1 -1
  3. package/cordis.patch.yml +3 -3
  4. package/docs/CHANGELOG.md +15 -0
  5. package/docs/agent-installation.md +19 -12
  6. package/docs/architecture.md +74 -74
  7. package/docs/desktop-migration-20260930.md +26 -26
  8. package/docs/development.md +7 -3
  9. package/docs/getting-started.md +17 -7
  10. package/docs/layout-progress.md +31 -31
  11. package/docs/market-listing.md +5 -3
  12. package/docs/npm-publishing.md +35 -11
  13. package/docs/package-name-migration.md +3 -3
  14. package/docs/planning-board.md +44 -44
  15. package/docs/presets.md +24 -24
  16. package/docs/release-process.md +45 -10
  17. package/docs/tavern-compatibility-audit-20261001.md +109 -109
  18. package/docs/test-report.md +139 -129
  19. package/docs/upgrade.md +3 -1
  20. package/docs/usage-review.md +13 -13
  21. package/lib/client.js +19 -14
  22. package/package.json +19 -14
  23. package/skills/cuigengji-maintenance/SKILL.md +2 -2
  24. package/src/adapters/dsh/prompt.js +36 -36
  25. package/src/adapters/dsh/rpc.js +96 -96
  26. package/src/adapters/dsh/skills.js +17 -17
  27. package/src/adapters/mcp/actions.js +6 -6
  28. package/src/adapters/mcp/client.js +172 -172
  29. package/src/adapters/mcp/server.js +40 -40
  30. package/src/application/bindings/session.js +72 -72
  31. package/src/application/queries/context.js +15 -15
  32. package/src/application/store.js +412 -412
  33. package/src/client/features/chapters/clipboard.ts +27 -27
  34. package/src/client/features/chapters/history.ts +11 -11
  35. package/src/client/features/chapters/index.jsx +118 -118
  36. package/src/client/features/chapters/sync.ts +155 -155
  37. package/src/client/features/chapters/useChapterSync.ts +39 -39
  38. package/src/client/features/context/index.jsx +22 -22
  39. package/src/client/features/memory/index.jsx +73 -73
  40. package/src/client/features/planning/Decorations.tsx +1 -1
  41. package/src/client/features/planning/Pages.tsx +11 -11
  42. package/src/client/features/planning/data.js +16 -16
  43. package/src/client/index.tsx +130 -130
  44. package/src/client/launcher.tsx +78 -78
  45. package/src/client/shared/creation.tsx +34 -34
  46. package/src/client/shared/detail-page.tsx +61 -61
  47. package/src/client/shared/drafts.js +17 -17
  48. package/src/client/shared/evidence.jsx +11 -11
  49. package/src/client/shared/groups.tsx +34 -34
  50. package/src/client/shared/preferences.tsx +104 -104
  51. package/src/client/shared/select-style.ts +25 -25
  52. package/src/client/shared/state.js +95 -95
  53. package/src/client/shared/ui.jsx +19 -19
  54. package/src/client/shared/workspace.tsx +11 -11
  55. package/src/client/style.ts +274 -274
  56. package/src/client/visual.ts +190 -190
  57. package/src/contracts/actions.js +19 -19
  58. package/src/contracts/planning.ts +52 -52
  59. package/src/domain/manuscript.ts +4 -4
  60. package/src/domain/planning/index.ts +113 -113
  61. package/src/domain/planning/model.ts +59 -59
  62. package/src/domain/preset/index.js +89 -89
  63. package/src/index.js +91 -91
  64. package/src/infrastructure/migrations/legacy.js +96 -96
  65. package/src/infrastructure/migrations/tavern.js +78 -78
  66. package/src/infrastructure/persistence/atomic-store.ts +80 -80
  67. package/src/infrastructure/persistence/project-layout.ts +1 -1
@@ -15,84 +15,84 @@ export class AtomicStore<T> {
15
15
  this.root=resolve(root);this.file=join(this.root,'store.json');this.pending=join(this.root,'store.pending.json');
16
16
  this.lockTimeoutMs=options.lockTimeoutMs??10000;this.empty=empty;this.validate=validate;
17
17
  }
18
- async acquire() {
19
- await mkdir(this.root, { recursive: true, mode: 0o700 });
20
- const lock = join(this.root, '.lock'); const started = Date.now();
21
- for (;;) {
22
- try {
23
- await mkdir(lock);
24
- try { await writeFile(join(lock, 'owner'), String(process.pid), { flag: 'wx', mode: 0o600 }); }
25
- catch (error) { await rmdir(lock).catch(() => {}); throw error; }
26
- return async () => { await unlink(join(lock, 'owner')); await rmdir(lock); };
27
- } catch (error) {
28
- if (errorCode(error) !== 'EEXIST') throw error;
29
- // Never reclaim by age: a slow live writer must retain exclusive ownership.
30
- try {
31
- const pid = Number(await readFile(join(lock, 'owner'), 'utf8'));
32
- if (Number.isSafeInteger(pid) && pid > 0) {
33
- try { process.kill(pid, 0); } catch (e) {
34
- if (errorCode(e) === 'ESRCH') {
35
- // Only one contender may reclaim a dead writer. Re-read ownership after
36
- // acquiring the claim, then move that directory before cleaning it up.
37
- const claim = join(lock, 'reclaim');
38
- try {
39
- await mkdir(claim);
40
- const latest = Number(await readFile(join(lock, 'owner'), 'utf8'));
41
- if (latest === pid) {
42
- const abandoned = join(this.root, `.dead-lock-${randomUUID()}`);
43
- await rename(lock, abandoned);
44
- await unlink(join(abandoned, 'owner'));
45
- await rmdir(join(abandoned, 'reclaim'));
46
- await rmdir(abandoned);
47
- } else await rmdir(claim);
48
- } catch { /* Another contender reclaimed the same dead writer. */ }
49
- }
50
- }
51
- }
52
- } catch { /* A writer may still be creating its owner file. */ }
53
- if (Date.now() - started >= this.lockTimeoutMs) fail('STORE_BUSY', '小说数据正在被另一操作使用,请稍后重试');
54
- await new Promise(r => setTimeout(r, 20));
55
- }
56
- }
57
- }
58
-
59
- async load(): Promise<T> {
60
- try {
61
- const pending = JSON.parse(await readFile(this.pending, 'utf8'));
62
- this.validate(pending);
63
- await rename(this.pending, this.file);
64
- } catch (e) { if (errorCode(e) !== 'ENOENT') throw e; }
65
- try {
66
- const state = JSON.parse(await readFile(this.file, 'utf8'));
67
- this.validate(state);
68
- return state;
69
- } catch (e) { if (errorCode(e) === 'ENOENT') return this.empty(); throw e; }
70
- }
71
-
72
- async save(state: T) {
73
- // A crash during staging leaves the last committed snapshot untouched.
74
- const staging = join(this.root, `store.stage-${randomUUID()}.json`);
75
- const handle = await open(staging, 'wx', 0o600);
76
- try { await handle.writeFile(JSON.stringify(state)); await handle.sync(); } finally { await handle.close(); }
77
- await rename(staging, this.pending);
78
- await this.syncDirectory();
79
- await rename(this.pending, this.file);
80
- await this.syncDirectory();
81
- }
82
- async syncDirectory() {
83
- // Directory handles are syncable on POSIX, but Windows commonly returns
84
- // EPERM/EISDIR/ENOTSUP for fsync even when the rename itself succeeded.
85
- // The staged file is still fsynced before each atomic promotion above, so
86
- // treat an unsupported directory barrier as best-effort on Windows while
87
- // surfacing real I/O failures everywhere else.
88
- try {
89
- const handle = await open(this.root, 'r');
90
- try { await handle.sync(); } finally { await handle.close(); }
91
- } catch (error) {
92
- const unsupported = new Set(['EBADF', 'EISDIR', 'EINVAL', 'ENOSYS', 'ENOTSUP', 'EPERM']);
93
- if (process.platform === 'win32' && unsupported.has(errorCode(error))) return;
94
- throw error;
95
- }
96
- }
97
-
18
+ async acquire() {
19
+ await mkdir(this.root, { recursive: true, mode: 0o700 });
20
+ const lock = join(this.root, '.lock'); const started = Date.now();
21
+ for (;;) {
22
+ try {
23
+ await mkdir(lock);
24
+ try { await writeFile(join(lock, 'owner'), String(process.pid), { flag: 'wx', mode: 0o600 }); }
25
+ catch (error) { await rmdir(lock).catch(() => {}); throw error; }
26
+ return async () => { await unlink(join(lock, 'owner')); await rmdir(lock); };
27
+ } catch (error) {
28
+ if (errorCode(error) !== 'EEXIST') throw error;
29
+ // Never reclaim by age: a slow live writer must retain exclusive ownership.
30
+ try {
31
+ const pid = Number(await readFile(join(lock, 'owner'), 'utf8'));
32
+ if (Number.isSafeInteger(pid) && pid > 0) {
33
+ try { process.kill(pid, 0); } catch (e) {
34
+ if (errorCode(e) === 'ESRCH') {
35
+ // Only one contender may reclaim a dead writer. Re-read ownership after
36
+ // acquiring the claim, then move that directory before cleaning it up.
37
+ const claim = join(lock, 'reclaim');
38
+ try {
39
+ await mkdir(claim);
40
+ const latest = Number(await readFile(join(lock, 'owner'), 'utf8'));
41
+ if (latest === pid) {
42
+ const abandoned = join(this.root, `.dead-lock-${randomUUID()}`);
43
+ await rename(lock, abandoned);
44
+ await unlink(join(abandoned, 'owner'));
45
+ await rmdir(join(abandoned, 'reclaim'));
46
+ await rmdir(abandoned);
47
+ } else await rmdir(claim);
48
+ } catch { /* Another contender reclaimed the same dead writer. */ }
49
+ }
50
+ }
51
+ }
52
+ } catch { /* A writer may still be creating its owner file. */ }
53
+ if (Date.now() - started >= this.lockTimeoutMs) fail('STORE_BUSY', '小说数据正在被另一操作使用,请稍后重试');
54
+ await new Promise(r => setTimeout(r, 20));
55
+ }
56
+ }
57
+ }
58
+
59
+ async load(): Promise<T> {
60
+ try {
61
+ const pending = JSON.parse(await readFile(this.pending, 'utf8'));
62
+ this.validate(pending);
63
+ await rename(this.pending, this.file);
64
+ } catch (e) { if (errorCode(e) !== 'ENOENT') throw e; }
65
+ try {
66
+ const state = JSON.parse(await readFile(this.file, 'utf8'));
67
+ this.validate(state);
68
+ return state;
69
+ } catch (e) { if (errorCode(e) === 'ENOENT') return this.empty(); throw e; }
70
+ }
71
+
72
+ async save(state: T) {
73
+ // A crash during staging leaves the last committed snapshot untouched.
74
+ const staging = join(this.root, `store.stage-${randomUUID()}.json`);
75
+ const handle = await open(staging, 'wx', 0o600);
76
+ try { await handle.writeFile(JSON.stringify(state)); await handle.sync(); } finally { await handle.close(); }
77
+ await rename(staging, this.pending);
78
+ await this.syncDirectory();
79
+ await rename(this.pending, this.file);
80
+ await this.syncDirectory();
81
+ }
82
+ async syncDirectory() {
83
+ // Directory handles are syncable on POSIX, but Windows commonly returns
84
+ // EPERM/EISDIR/ENOTSUP for fsync even when the rename itself succeeded.
85
+ // The staged file is still fsynced before each atomic promotion above, so
86
+ // treat an unsupported directory barrier as best-effort on Windows while
87
+ // surfacing real I/O failures everywhere else.
88
+ try {
89
+ const handle = await open(this.root, 'r');
90
+ try { await handle.sync(); } finally { await handle.close(); }
91
+ } catch (error) {
92
+ const unsupported = new Set(['EBADF', 'EISDIR', 'EINVAL', 'ENOSYS', 'ENOTSUP', 'EPERM']);
93
+ if (process.platform === 'win32' && unsupported.has(errorCode(error))) return;
94
+ throw error;
95
+ }
96
+ }
97
+
98
98
  }
@@ -221,4 +221,4 @@ export function splitWorkspace(state: Workspace, directories = planProjectDirect
221
221
  // Publishing the library last marks a fully staged initial migration.
222
222
  files.set('library.json', JSON.stringify({ format: 'cuigengji-library', storageVersion, metadata: without(state, ['novels', 'bindings', 'requests']), novels: Object.fromEntries(Object.entries(state.novels).map(([id, novel]) => [id, libraryRow(novel)])), directories } satisfies Library));
223
223
  return files;
224
- }
224
+ }