dsh-solution-ledger 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -8,13 +8,27 @@
8
8
 
9
9
  ## 安装
10
10
 
11
+ ### 从 npm 安装(推荐)
12
+
13
+ ```bash
14
+ npm i dsh-solution-ledger
15
+ ```
16
+
17
+ 或直接让 DSH 装上并启用:
18
+
19
+ ```bash
20
+ dsh plugin --profile <profile 名> add dsh-solution-ledger
21
+ ```
22
+
23
+ 也可以打开 Web 的 **Plugins** 页面,点 Add,填 `dsh-solution-ledger`。
24
+
11
25
  ### 从 GitHub 安装
12
26
 
13
27
  ```bash
14
28
  dsh plugin --profile <profile 名> add github:Catwb/dsh-solution-ledger
15
29
  ```
16
30
 
17
- 也可以打开 Web 的 **Plugins** 页面,点 Add,填 `github:Catwb/dsh-solution-ledger`。
31
+ 适合想跟最新提交的场合;npm 上的版本更稳。
18
32
 
19
33
  安装后侧边栏顶部图标排会多出一个账本图标。修改插件代码后,在 Plugins 页面关掉再打开以重新加载 Host 半;浏览器端还需要刷新页面。
20
34
 
@@ -61,6 +75,8 @@ git clone https://github.com/Catwb/dsh-solution-ledger.git
61
75
 
62
76
  换句话说:**如果一条记录永远不会出现在报错里、也不会改变任何人下一步的决定,那它是日志,不是账本条目。**
63
77
 
78
+ 写进去的草稿如果 30 天内**从未被任何检索或推送命中**,会自动归档(`draftArchiveAfterDays`)——即使模型偶尔写进一条实现说明,没人用的小记录也会自己沉底,不必手动清理。归档不等于删除:条目仍在文件里,可在界面里「取消归档」恢复。
79
+
64
80
  | 参数 | 必填 | 说明 |
65
81
  |---|---|---|
66
82
  | `kind` | 是 | `troubleshoot`(修好的故障)或 `decision`(选定/否决的路线) |
@@ -126,6 +142,7 @@ Host 半为此注册了三条路由:`GET /solution-ledger/list`、`POST /solut
126
142
  | `pushMinScore` | `12` | 自动推送的最低相关度。低于它的匹配不打扰模型 |
127
143
  | `maxEntries` | `2000` | 硬上限;超出后按更新时间删除最旧的**已归档**条目 |
128
144
  | `archiveAfterDays` | `90` | 超过这么多天未被命中的条目移出检索(不删除) |
145
+ | `draftArchiveAfterDays` | `30` | 草稿且**从未被命中**,超过这么多天自动归档(不删除) |
129
146
  | `statePath` | `''` | 空则用 `$DSH_HOME/solution-ledger.json` |
130
147
 
131
148
  ## 限制
package/cordis.patch.yml CHANGED
@@ -12,5 +12,8 @@
12
12
  maxEntries: 2000
13
13
  # Entries untouched for this many days are archived out of search.
14
14
  archiveAfterDays: 90
15
+ # An unreviewed draft nobody ever searched for is archived after this
16
+ # many days, so stray implementation notes do not pile up.
17
+ draftArchiveAfterDays: 30
15
18
  # Absolute path for the JSON store. Empty uses $DSH_HOME/solution-ledger.json.
16
19
  statePath: ''
package/lib/index.js CHANGED
@@ -34,6 +34,7 @@ const DEFAULTS = {
34
34
  pushMinScore: 12,
35
35
  maxEntries: 2000,
36
36
  archiveAfterDays: 90,
37
+ draftArchiveAfterDays: 30,
37
38
  statePath: '',
38
39
  }
39
40
 
@@ -56,6 +57,7 @@ function normalizeConfig(raw) {
56
57
  pushMinScore: int(source.pushMinScore, DEFAULTS.pushMinScore, 1, 100),
57
58
  maxEntries: int(source.maxEntries, DEFAULTS.maxEntries, 10, 100_000),
58
59
  archiveAfterDays: int(source.archiveAfterDays, DEFAULTS.archiveAfterDays, 1, 3650),
60
+ draftArchiveAfterDays: int(source.draftArchiveAfterDays, DEFAULTS.draftArchiveAfterDays, 1, 3650),
59
61
  statePath: typeof source.statePath === 'string' ? source.statePath : DEFAULTS.statePath,
60
62
  }
61
63
  }
@@ -71,18 +73,32 @@ function newId() {
71
73
  /**
72
74
  * Age out entries and enforce the ceiling, in place, inside a write.
73
75
  * Deprecated entries leave search immediately; so does anything the user has
74
- * not touched in `archiveAfterDays`. Nothing is deleted until the ceiling is
75
- * actually exceeded, so an old entry stays recoverable by default.
76
+ * not touched in `archiveAfterDays`. A draft that nobody ever searched for
77
+ * leaves on the shorter `draftArchiveAfterDays` clock: models do write the
78
+ * occasional note that is an implementation remark rather than a problem, and
79
+ * without this those accumulate forever as unreviewed drafts. Nothing is
80
+ * deleted until the ceiling is actually exceeded, so every archived entry stays
81
+ * recoverable.
76
82
  * @param ledger - the ledger being written.
77
83
  * @param config - resolved plugin config.
78
84
  */
79
85
  function maintainInPlace(ledger, config) {
80
- const cutoff = Date.now() - config.archiveAfterDays * DAY_MS
86
+ const now = Date.now()
87
+ const cutoff = now - config.archiveAfterDays * DAY_MS
88
+ const draftCutoff = now - config.draftArchiveAfterDays * DAY_MS
81
89
  for (const snapshot of ledger.all()) {
82
90
  const entry = ledger.get(snapshot.id)
83
91
  if (entry === undefined || entry.archived === true) continue
84
92
  const lastUse = entry.lastHitAt > 0 ? entry.lastHitAt : entry.createdAt
85
- if (entry.status === 'deprecated' || lastUse < cutoff) entry.archived = true
93
+ if (entry.status === 'deprecated' || lastUse < cutoff) {
94
+ entry.archived = true
95
+ continue
96
+ }
97
+ // Never surfaced, never confirmed, and older than the draft clock: this is
98
+ // the shape of a remark that was never useful to anyone.
99
+ if (entry.status === 'draft' && entry.hits === 0 && entry.createdAt < draftCutoff) {
100
+ entry.archived = true
101
+ }
86
102
  }
87
103
  if (ledger.size <= config.maxEntries) return
88
104
  const oldestArchived = ledger
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "dsh-solution-ledger",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/Catwb/dsh-solution-ledger.git"
8
+ },
5
9
  "type": "module",
6
10
  "description": "Global problem-solving ledger: records troubleshooting and design decisions, searches them before debugging, and surfaces a matching entry when a tool fails. Managed from a sidebar drawer.",
7
11
  "main": "./lib/index.js",