dsh-sixlayer-memory 2.0.2 → 2.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # 变更记录 · dsh-sixlayer-memory(六层记忆底座)
2
2
 
3
+ ## 2.0.3 — 2026-11-21
4
+
5
+ 主题:**发布到 npm**。
6
+
7
+ ### 变更
8
+
9
+ - `repository` / `bugs` / `homepage` 从占位符 `<your-account>` 换成真实仓库 `github.com/z9134/dsh-sixlayer-memory`
10
+ (2.0.2 已经发到 npm,但页面上的仓库链接指向占位符,删不掉,只能靠新版本覆盖元数据)
11
+ - README 首屏加 npm / license / DSH 徽章与视频链接
12
+
13
+ ### 发布
14
+
15
+ - `npm publish` → https://www.npmjs.com/package/dsh-sixlayer-memory
16
+ - 全程走 `registry.npmjs.org`(`www.npmjs.com` 在本机 403,Web 登录走不通,用 granular token + Bypass 2FA 发布)
17
+
18
+ ---
19
+
3
20
  ## 2.0.2 — 2026-11-20
4
21
 
5
22
  主题:**点一个圆球,就能看这条记忆的全部**。
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # dsh-sixlayer-memory · 六层记忆底座
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/dsh-sixlayer-memory?style=flat-square&label=npm)](https://www.npmjs.com/package/dsh-sixlayer-memory)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](LICENSE)
5
+ [![DSH](https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.1%20%3C0.3.0-4c6ef5?style=flat-square)](https://github.com/deepseek-ai/deepseek-harness)
6
+
3
7
  > **会先审后记、还带审计链的本地记忆。**
4
8
  > 每一轮按你的输入自动召回;不确定的东西不会直接变成事实;每个动作都能倒查。
5
9
 
@@ -7,7 +11,9 @@
7
11
  dsh plugin --profile desktop add dsh-sixlayer-memory
8
12
  ```
9
13
 
10
- **当前版本**:2.0.2 · **32 个工具** · schema v9 · 零外部依赖 · 回归 31 个套件全绿
14
+ **当前版本**:2.0.3 · **32 个工具** · schema v9 · 零外部依赖 · 回归 31 个套件全绿
15
+
16
+ 📦 [npm](https://www.npmjs.com/package/dsh-sixlayer-memory) · 🎬 [40 秒介绍视频](media/intro-40s.mp4) · 📝 [变更记录](CHANGELOG.md)
11
17
 
12
18
  ---
13
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sixlayer-memory",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "private": false,
5
5
  "description": "DSH 工作台:六层记忆底座(每轮自动召回 + 候选沉淀 + 闸门审计)+ 零件化,支持 QQ 随身使用。",
6
6
  "type": "module",
@@ -105,12 +105,12 @@
105
105
  ],
106
106
  "repository": {
107
107
  "type": "git",
108
- "url": "git+https://github.com/<your-account>/dsh-sixlayer-memory.git"
108
+ "url": "git+https://github.com/z9134/dsh-sixlayer-memory.git"
109
109
  },
110
110
  "bugs": {
111
- "url": "https://github.com/<your-account>/dsh-sixlayer-memory/issues"
111
+ "url": "https://github.com/z9134/dsh-sixlayer-memory/issues"
112
112
  },
113
- "homepage": "https://github.com/<your-account>/dsh-sixlayer-memory#readme",
113
+ "homepage": "https://github.com/z9134/dsh-sixlayer-memory#readme",
114
114
  "publishConfig": {
115
115
  "access": "public"
116
116
  }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * push-via-api.mjs —— 用 GitHub REST API 把本地仓库推到 GitHub。
3
+ *
4
+ * 为什么要这个:这台机器上 github.com:443 不通(git push / GCM 登录都会卡死),
5
+ * 但 api.github.com:443 通。所以走 Git Data API 建库 + 提交树,不依赖 git 传输。
6
+ *
7
+ * 用法:
8
+ * $env:GITHUB_TOKEN='ghp_xxx' # classic PAT,勾 repo 权限
9
+ * node tools/push-via-api.mjs
10
+ *
11
+ * 只读本地 git 索引(git ls-files),不会把 .gitignore 排除的东西传上去。
12
+ */
13
+ import fs from 'node:fs'
14
+ import path from 'node:path'
15
+ import { execFileSync } from 'node:child_process'
16
+
17
+ const OWNER = 'z9134'
18
+ const REPO = 'dsh-sixlayer-memory'
19
+ const ROOT = process.env.REPO_ROOT ?? 'D:/001/CH002/dsh-memory-core'
20
+ const TOKEN = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? ''
21
+
22
+ if (!TOKEN) {
23
+ console.error('缺少 GITHUB_TOKEN。先在 https://github.com/settings/tokens 建一个勾了 repo 的 token,然后:')
24
+ console.error(" $env:GITHUB_TOKEN='ghp_...'")
25
+ console.error(' node tools/push-via-api.mjs')
26
+ process.exit(2)
27
+ }
28
+
29
+ const API = 'https://api.github.com'
30
+
31
+ async function callOnce(method, url, body) {
32
+ const res = await fetch(API + url, {
33
+ method,
34
+ headers: {
35
+ authorization: `Bearer ${TOKEN}`,
36
+ accept: 'application/vnd.github+json',
37
+ 'x-github-api-version': '2022-11-28',
38
+ 'user-agent': 'dsh-sixlayer-memory-release',
39
+ ...(body ? { 'content-type': 'application/json' } : {}),
40
+ },
41
+ body: body ? JSON.stringify(body) : undefined,
42
+ })
43
+ const text = await res.text()
44
+ let json = null
45
+ try {
46
+ json = text ? JSON.parse(text) : null
47
+ } catch {
48
+ /* 非 JSON 响应 */
49
+ }
50
+ if (!res.ok) {
51
+ const msg = json?.message ?? text.slice(0, 300)
52
+ throw new Error(`${method} ${url} -> ${res.status} ${msg}`)
53
+ }
54
+ return json
55
+ }
56
+
57
+ /** 网络抖动重试:断线/超时重来 3 次,4xx 直接抛。 */
58
+ async function call(method, url, body) {
59
+ let last
60
+ for (let attempt = 1; attempt <= 3; attempt += 1) {
61
+ try {
62
+ return await callOnce(method, url, body)
63
+ } catch (error) {
64
+ last = error
65
+ const msg = String(error?.message ?? '')
66
+ const retriable = /fetch failed|ECONNRESET|ETIMEDOUT|EAI_AGAIN|socket hang up|network|-> 5\d\d/.test(msg)
67
+ if (!retriable) throw error
68
+ if (attempt < 3) await new Promise((r) => setTimeout(r, 600 * attempt))
69
+ }
70
+ }
71
+ throw last
72
+ }
73
+
74
+ async function ensureRepo() {
75
+ try {
76
+ const repo = await call('GET', `/repos/${OWNER}/${REPO}`)
77
+ console.log(`仓库已存在:${repo.html_url}`)
78
+ return repo
79
+ } catch (error) {
80
+ if (!/-> 404/.test(error.message)) throw error
81
+ }
82
+ const repo = await call('POST', '/user/repos', {
83
+ name: REPO,
84
+ description: '会先审后记、还带审计链的本地记忆 · DSH 六层记忆底座',
85
+ homepage: '',
86
+ private: false,
87
+ has_issues: true,
88
+ has_wiki: false,
89
+ auto_init: false,
90
+ })
91
+ console.log(`已创建仓库:${repo.html_url}`)
92
+ return repo
93
+ }
94
+
95
+ /**
96
+ * 空仓库连 git/trees 都返回 409「Git Repository is empty」,
97
+ * 唯一可靠的办法是先用 Contents API 写一个文件把仓库"点亮",
98
+ * 再用 blobs/tree/commit 覆盖上去。这里直接写真实 README。
99
+ */
100
+ async function bootstrapIfEmpty() {
101
+ try {
102
+ await call('GET', `/repos/${OWNER}/${REPO}/git/ref/heads/main`)
103
+ return false
104
+ } catch (error) {
105
+ if (!/-> 404|-> 409/.test(error.message)) throw error
106
+ }
107
+ const readme = fs.readFileSync(path.join(ROOT, 'README.md'))
108
+ await call('PUT', `/repos/${OWNER}/${REPO}/contents/README.md`, {
109
+ message: 'init: README',
110
+ content: readme.toString('base64'),
111
+ })
112
+ console.log('已用 README 初始化 main 分支(空仓库不能直接传 blob/tree)')
113
+ return true
114
+ }
115
+
116
+ function trackedFiles() {
117
+ const out = execFileSync('git', ['-C', ROOT, 'ls-files', '-z'], { encoding: 'utf8' })
118
+ return out.split('\0').filter(Boolean)
119
+ }
120
+
121
+ async function uploadBlob(rel) {
122
+ const abs = path.join(ROOT, rel)
123
+ const content = fs.readFileSync(abs)
124
+ const blob = await call('POST', `/repos/${OWNER}/${REPO}/git/blobs`, {
125
+ content: content.toString('base64'),
126
+ encoding: 'base64',
127
+ })
128
+ return blob.sha
129
+ }
130
+
131
+ async function main() {
132
+ const me = await call('GET', '/user')
133
+ if (me.login !== OWNER) throw new Error(`token 属于 ${me.login},不是 ${OWNER}`)
134
+ console.log(`身份:${me.login}`)
135
+
136
+ await ensureRepo()
137
+ await bootstrapIfEmpty()
138
+
139
+ const files = trackedFiles()
140
+ console.log(`本地文件:${files.length} 个`)
141
+
142
+ const entries = []
143
+ let done = 0
144
+ const concurrency = 4
145
+ let cursor = 0
146
+ async function worker() {
147
+ while (cursor < files.length) {
148
+ const rel = files[cursor++]
149
+ const sha = await uploadBlob(rel)
150
+ entries.push({ path: rel.split(path.sep).join('/'), mode: '100644', type: 'blob', sha })
151
+ done += 1
152
+ if (done % 20 === 0) console.log(` 已上传 ${done}/${files.length}`)
153
+ }
154
+ }
155
+ await Promise.all(Array.from({ length: concurrency }, worker))
156
+ console.log(` 已上传 ${done}/${files.length}`)
157
+
158
+ const tree = await call('POST', `/repos/${OWNER}/${REPO}/git/trees`, { tree: entries })
159
+ const message = execFileSync('git', ['-C', ROOT, 'log', '-1', '--pretty=%s'], { encoding: 'utf8' }).trim()
160
+ const commit = await call('POST', `/repos/${OWNER}/${REPO}/git/commits`, {
161
+ message: `${message}\n\n(经 GitHub API 推送)`,
162
+ tree: tree.sha,
163
+ parents: [],
164
+ })
165
+
166
+ let hasMain = true
167
+ try {
168
+ await call('GET', `/repos/${OWNER}/${REPO}/git/ref/heads/main`)
169
+ } catch (error) {
170
+ if (!/-> 404|-> 409/.test(error.message)) throw error
171
+ hasMain = false
172
+ }
173
+ if (hasMain) {
174
+ await call('PATCH', `/repos/${OWNER}/${REPO}/git/refs/heads/main`, { sha: commit.sha, force: true })
175
+ } else {
176
+ await call('POST', `/repos/${OWNER}/${REPO}/git/refs`, { ref: 'refs/heads/main', sha: commit.sha })
177
+ }
178
+
179
+ console.log('')
180
+ console.log(`完成:https://github.com/${OWNER}/${REPO}/tree/main`)
181
+ console.log(`commit ${commit.sha.slice(0, 10)} · ${entries.length} 个文件`)
182
+ }
183
+
184
+ main().catch((error) => {
185
+ console.error('失败:' + (error?.message ?? String(error)))
186
+ process.exit(1)
187
+ })