dsh-dev-modes 1.1.3 → 1.1.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 (2) hide show
  1. package/package.json +1 -1
  2. package/quiet-run/index.js +43 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dev-modes",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "description": "Three DeepSeek Harness Agent presets in one bundle — plus the per-session isolation and quiet-run switches: software development, game development, and read-only discussion, with the matching delivery and engine workflows bundled as skills.",
6
6
  "author": "qingfengshangnanzhi",
@@ -16,6 +16,22 @@ import { fileURLToPath } from 'node:url';
16
16
  const HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
17
17
  const STORE_DIR = path.join(HOME, 'storages', 'dsh-quiet-run');
18
18
  const STORE_FILE = path.join(STORE_DIR, 'state.json');
19
+ const LOG_FILE = path.join(STORE_DIR, 'requests.log');
20
+
21
+ /** 记一行请求日志:排查"点了开关但没生效"时,能看清前端到底传了哪个会话。 */
22
+ function logRequest(entry) {
23
+ try {
24
+ fs.mkdirSync(STORE_DIR, { recursive: true });
25
+ fs.appendFileSync(LOG_FILE, JSON.stringify({ t: Date.now(), ...entry }) + '\n', 'utf8');
26
+ const stat = fs.statSync(LOG_FILE);
27
+ if (stat.size > 200 * 1024) {
28
+ const lines = fs.readFileSync(LOG_FILE, 'utf8').trim().split('\n').slice(-200);
29
+ fs.writeFileSync(LOG_FILE, lines.join('\n') + '\n', 'utf8');
30
+ }
31
+ } catch {
32
+ /* 日志失败不影响功能 */
33
+ }
34
+ }
19
35
 
20
36
  /** 与包一起分发的窗口搬运脚本(绝对路径,写进规则里让模型直接可用)。 */
21
37
  const HELPER = path.join(
@@ -238,6 +254,7 @@ export function apply(ctx) {
238
254
  const url = new URL(req.url || '/', 'http://127.0.0.1');
239
255
  const asked = url.searchParams.get('sessionId');
240
256
  const sessionId = asked || activeSessionId;
257
+ logRequest({ kind: 'state', asked: asked ?? null, resolved: sessionId, fromActive: !asked });
241
258
  if (!sessionId) {
242
259
  sendJson(res, 200, { sessionId: null, quiet: true, ready: false, diag });
243
260
  return;
@@ -262,6 +279,13 @@ export function apply(ctx) {
262
279
  }
263
280
  const body = await readJsonBody(req);
264
281
  const sessionId = body.sessionId || activeSessionId;
282
+ logRequest({
283
+ kind: 'set',
284
+ bodySession: body.sessionId ?? null,
285
+ resolved: sessionId,
286
+ fromActive: !body.sessionId,
287
+ value: body.quiet,
288
+ });
265
289
  if (!sessionId) {
266
290
  sendJson(res, 400, { error: 'no active session yet' });
267
291
  return;
@@ -272,9 +296,28 @@ export function apply(ctx) {
272
296
  },
273
297
  });
274
298
 
299
+ const dumpLog = c.webServer.register({
300
+ kind: 'exact',
301
+ path: '/dsh-quiet-run/log',
302
+ handler: async (req, res) => {
303
+ let lines = [];
304
+ try {
305
+ lines = fs.readFileSync(LOG_FILE, 'utf8').trim().split('\n').slice(-60);
306
+ } catch {
307
+ lines = [];
308
+ }
309
+ res.writeHead(200, {
310
+ 'content-type': 'application/json; charset=utf-8',
311
+ 'cache-control': 'no-store',
312
+ });
313
+ res.end(JSON.stringify({ activeSessionId, entries: lines }));
314
+ },
315
+ });
316
+
275
317
  return () => {
276
318
  state();
277
319
  toggle();
320
+ dumpLog();
278
321
  };
279
322
  });
280
323
  });