@ppdocs/mcp 3.2.19 → 3.2.21

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.
@@ -1,116 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import * as os from 'os';
4
- export class DiscussionManager {
5
- static getFilePath() {
6
- const dir = path.join(os.homedir(), '.ppdocs');
7
- if (!fs.existsSync(dir))
8
- fs.mkdirSync(dir, { recursive: true });
9
- return path.join(dir, 'discussions.json');
10
- }
11
- static readAll() {
12
- try {
13
- const file = this.getFilePath();
14
- if (!fs.existsSync(file))
15
- return [];
16
- return JSON.parse(fs.readFileSync(file, 'utf-8'));
17
- }
18
- catch {
19
- return [];
20
- }
21
- }
22
- static writeAll(data) {
23
- fs.writeFileSync(this.getFilePath(), JSON.stringify(data, null, 2), 'utf-8');
24
- }
25
- static listActive() {
26
- return this.readAll()
27
- .filter(t => t.status === 'active')
28
- .map(({ messages, ...rest }) => rest);
29
- }
30
- static readByIds(ids) {
31
- return this.readAll().filter(t => ids.includes(t.id));
32
- }
33
- static create(title, initiator, participants, content) {
34
- const id = `req_${Math.random().toString(36).substring(2, 9)}`;
35
- const now = new Date().toISOString();
36
- // 确保发起方始终在参与列表中
37
- const allParticipants = participants.includes(initiator) ? [...participants] : [initiator, ...participants];
38
- const topic = {
39
- id,
40
- title,
41
- initiator,
42
- participants: allParticipants,
43
- summary: "等待各方回复中...",
44
- status: 'active',
45
- created_at: now,
46
- updated_at: now,
47
- messages: [{
48
- id: `msg_${Math.random().toString(36).substring(2, 9)}`,
49
- sender: initiator,
50
- content,
51
- timestamp: now
52
- }]
53
- };
54
- const all = this.readAll();
55
- all.push(topic);
56
- this.writeAll(all);
57
- return id;
58
- }
59
- static reply(id, sender, content, newSummary) {
60
- const all = this.readAll();
61
- const topic = all.find(t => t.id === id);
62
- if (!topic || topic.status !== 'active')
63
- return false;
64
- const now = new Date().toISOString();
65
- topic.messages.push({
66
- id: `msg_${Math.random().toString(36).substring(2, 9)}`,
67
- sender,
68
- content,
69
- timestamp: now
70
- });
71
- topic.updated_at = now;
72
- if (newSummary) {
73
- topic.summary = newSummary;
74
- }
75
- // Auto add to participants if not exists
76
- if (!topic.participants.includes(sender)) {
77
- topic.participants.push(sender);
78
- }
79
- this.writeAll(all);
80
- return true;
81
- }
82
- static getAndRemove(id) {
83
- const all = this.readAll();
84
- const index = all.findIndex(t => t.id === id);
85
- if (index === -1)
86
- return null;
87
- const topic = all.splice(index, 1)[0];
88
- this.writeAll(all);
89
- return topic;
90
- }
91
- /** 按ID删除讨论(不归档,直接删除) */
92
- static delete(id) {
93
- const all = this.readAll();
94
- const index = all.findIndex(t => t.id === id);
95
- if (index === -1)
96
- return false;
97
- all.splice(index, 1);
98
- this.writeAll(all);
99
- return true;
100
- }
101
- /** 清理过期讨论(默认7天不活跃) */
102
- static cleanExpired(days = 7) {
103
- const all = this.readAll();
104
- const cutoff = Date.now() - days * 86400000;
105
- const before = all.length;
106
- const filtered = all.filter(t => new Date(t.updated_at).getTime() > cutoff);
107
- if (filtered.length < before) {
108
- this.writeAll(filtered);
109
- }
110
- return before - filtered.length;
111
- }
112
- /** 获取活跃讨论数量 */
113
- static activeCount() {
114
- return this.readAll().filter(t => t.status === 'active').length;
115
- }
116
- }