@goodandready/dsh-messenger-gateway 0.4.25 → 0.4.27
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/lib/commands.js +10 -0
- package/lib/config.js +11 -0
- package/lib/cost-tracker.js +228 -0
- package/lib/gateway-commands.js +203 -6
- package/lib/gateway-turn.js +63 -1
- package/lib/gateway.js +57 -2
- package/lib/memory-brain.js +273 -0
- package/lib/outbox.js +262 -0
- package/lib/workspace.js +112 -1
- package/package.json +1 -1
package/lib/workspace.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve, normalize, basename } from 'node:path'
|
|
2
2
|
import { statSync, realpathSync, existsSync } from 'node:fs'
|
|
3
3
|
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
4
5
|
import { randomUUID } from 'node:crypto'
|
|
5
6
|
import os from 'node:os'
|
|
6
7
|
import path from 'node:path'
|
|
@@ -146,4 +147,114 @@ export async function registerSessionInWorkspace(ctx, sessionId, cwd, logger) {
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
return false
|
|
149
|
-
}
|
|
150
|
+
}
|
|
151
|
+
import { writeJsonAtomicSync } from "./storage-atomic.js"
|
|
152
|
+
|
|
153
|
+
export function resolveTopicWorkspacesStoragePath(config = {}) {
|
|
154
|
+
if (config.topicWorkspacesStoragePath) return config.topicWorkspacesStoragePath
|
|
155
|
+
const dshHome = process.env.DSH_HOME || path.join(os.homedir(), ".dsh")
|
|
156
|
+
return path.join(dshHome, "storages", "topic-workspaces.json")
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function inspectGitWorkspace(dirPath) {
|
|
160
|
+
try {
|
|
161
|
+
const gitPath = path.join(dirPath, ".git")
|
|
162
|
+
if (existsSync(gitPath)) {
|
|
163
|
+
const st = statSync(gitPath)
|
|
164
|
+
if (st.isDirectory()) {
|
|
165
|
+
return { isGit: true, isWorktree: false }
|
|
166
|
+
}
|
|
167
|
+
if (st.isFile()) {
|
|
168
|
+
const content = readFileSync(gitPath, "utf8")
|
|
169
|
+
const match = content.match(/gitdir:\s*(.+)/i)
|
|
170
|
+
return { isGit: true, isWorktree: true, gitdir: match ? match[1].trim() : null }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} catch {
|
|
174
|
+
// not a git repo
|
|
175
|
+
}
|
|
176
|
+
return { isGit: false, isWorktree: false }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function createTopicWorkspaceStore(filePath, { logger } = {}) {
|
|
180
|
+
let cache = { workspaces: {} }
|
|
181
|
+
try {
|
|
182
|
+
if (existsSync(filePath)) {
|
|
183
|
+
const raw = JSON.parse(readFileSync(filePath, "utf8"))
|
|
184
|
+
if (raw && typeof raw === "object" && raw.workspaces) {
|
|
185
|
+
cache = raw
|
|
186
|
+
} else if (raw && typeof raw === "object") {
|
|
187
|
+
cache = { workspaces: raw }
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} catch (err) {
|
|
191
|
+
if (err?.code !== "ENOENT") {
|
|
192
|
+
logger?.warn?.(`[dsh-messenger-gateway] topic-workspaces load error: ${err?.message || err}`)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function save() {
|
|
197
|
+
try {
|
|
198
|
+
writeJsonAtomicSync(filePath, cache)
|
|
199
|
+
} catch (err) {
|
|
200
|
+
logger?.warn?.(`[dsh-messenger-gateway] topic-workspaces save error: ${err?.message || err}`)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function makeKey(chatId, threadId = 0) {
|
|
205
|
+
const tid = Number(threadId) || 0
|
|
206
|
+
return tid > 0 ? `${chatId}:${tid}` : String(chatId)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
get(chatId, threadId = 0) {
|
|
211
|
+
if (chatId === undefined || chatId === null) return null
|
|
212
|
+
const key = makeKey(chatId, threadId)
|
|
213
|
+
if (cache.workspaces[key]) return { ...cache.workspaces[key] }
|
|
214
|
+
if (threadId) {
|
|
215
|
+
const baseKey = String(chatId)
|
|
216
|
+
if (cache.workspaces[baseKey]) return { ...cache.workspaces[baseKey] }
|
|
217
|
+
}
|
|
218
|
+
return null
|
|
219
|
+
},
|
|
220
|
+
set(chatId, threadId = 0, binding = {}) {
|
|
221
|
+
if (chatId === undefined || chatId === null) return
|
|
222
|
+
const key = makeKey(chatId, threadId)
|
|
223
|
+
cache.workspaces[key] = {
|
|
224
|
+
path: binding.path,
|
|
225
|
+
name: binding.name || basename(binding.path),
|
|
226
|
+
role: binding.role || null,
|
|
227
|
+
worktree: Boolean(binding.worktree),
|
|
228
|
+
boundAt: binding.boundAt || new Date().toISOString(),
|
|
229
|
+
}
|
|
230
|
+
save()
|
|
231
|
+
},
|
|
232
|
+
delete(chatId, threadId = 0) {
|
|
233
|
+
if (chatId === undefined || chatId === null) return false
|
|
234
|
+
const key = makeKey(chatId, threadId)
|
|
235
|
+
if (cache.workspaces[key]) {
|
|
236
|
+
delete cache.workspaces[key]
|
|
237
|
+
save()
|
|
238
|
+
return true
|
|
239
|
+
}
|
|
240
|
+
return false
|
|
241
|
+
},
|
|
242
|
+
list(chatId) {
|
|
243
|
+
if (chatId === undefined || chatId === null) return []
|
|
244
|
+
const prefix = `${chatId}:`
|
|
245
|
+
const baseKey = String(chatId)
|
|
246
|
+
const results = []
|
|
247
|
+
for (const [key, val] of Object.entries(cache.workspaces)) {
|
|
248
|
+
if (key === baseKey || key.startsWith(prefix)) {
|
|
249
|
+
const parts = key.split(":")
|
|
250
|
+
const tid = parts[1] ? Number(parts[1]) : 0
|
|
251
|
+
results.push({ threadId: tid, ...val })
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return results
|
|
255
|
+
},
|
|
256
|
+
all() {
|
|
257
|
+
return { ...cache.workspaces }
|
|
258
|
+
},
|
|
259
|
+
}
|
|
260
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-messenger-gateway",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.27",
|
|
4
4
|
"description": "Telegram messenger bridge for DeepSeek Harness: sessions, steer, homes, inline asks, notify bridge, and optional TTS voice notes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|