@suifei/dsh-ai-team 0.4.101 → 0.4.104
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 +51 -0
- package/lib/vendor/skillopt/skillopt_sleep/__main__.py +10 -2
- package/lib/vendor/skillopt/skillopt_sleep/config.py +7 -0
- package/lib/vendor/skillopt/skillopt_sleep/dsh_decode.mjs +61 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_dsh.py +279 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_sources.py +11 -0
- package/lib/vendor/skillopt/skillopt_sleep/scheduler.py +48 -15
- package/lib/vendor/skillopt/src/index.js +1 -1
- package/package.json +3 -1
- package/skills/skillopt-sleep/SKILL.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.104 - 2026-11-16
|
|
4
|
+
|
|
5
|
+
**切到 dsh 来源后的两处实机缺陷**
|
|
6
|
+
|
|
7
|
+
- **handoff 夜间空钉永久复用**:handoff 后端把一轮采集到的会话钉在 `.skillopt-sleep-handoff/digests.json`,
|
|
8
|
+
下一轮直接复用以保护已有回答。「没挖出任务」分支只推进采集窗、不撤钉——il2c 14:26 一次 `auto` 来源的运行
|
|
9
|
+
留下空钉(0 个会话),之后每晚都复用它,切到 `dsh` 后 10 个在册会话照样 `no tasks mined`。现在无任务即撤钉
|
|
10
|
+
(此时没有待回答的调用,撤钉不丢任何东西);
|
|
11
|
+
- **「列出已排程的项目」仍为空**:0.4.103 修了解码,但 schtasks 报的是任务路径 `"\SkillOpt-Sleep-…"`,按裸前缀
|
|
12
|
+
匹配永远不中。解析抽成 `_parse_win_task_names` 并去掉前导 `\`;实机 A/B:修复前 `[]`,修复后列出
|
|
13
|
+
`SkillOpt-Sleep-12d591e63a2d03aa9d7f`;
|
|
14
|
+
- 测试:`test/skillopt-dsh-source.test.js` 新增 2 例(隔离 HOME 跑两晚 `run --backend handoff --source dsh`,去掉修复即
|
|
15
|
+
失败;用实机 schtasks 输出样本解析任务名);
|
|
16
|
+
|
|
17
|
+
## 0.4.103 - 2026-11-16
|
|
18
|
+
|
|
19
|
+
**夜间 SkillOpt 环能从 DSH 会话里学习**
|
|
20
|
+
|
|
21
|
+
- **新增 `dsh` 会话来源**:引擎此前只认 claude/codex/copilot/cursor/pi/opencode,DeepSeek Harness 的会话
|
|
22
|
+
(含文渊阁成员)一条也读不到——il2c 里 agent 写进 `~/.skillopt-sleep/config.json` 的
|
|
23
|
+
`transcript_source: "dsh_team"` 让引擎每晚报 `Unknown transcript source`,删掉后又只扫到 0 个会话。
|
|
24
|
+
`harvest_dsh.py` 读 `<DSH_HOME>/sessions/*/*/session.v4.jsonl.zstd`:按会话头的 `cwd` 匹配项目(只解码
|
|
25
|
+
首行即可排除别的项目)。`user/message` 按 `source.kind` 取意图:`user`(人)、`agent-message`(文渊阁的
|
|
26
|
+
任务唤醒以 relay 投递,il2c 成员会话 37 条 relay 对 1 条 user)、`ai-team`(插件纠偏,同时记为负反馈
|
|
27
|
+
`neg:ai-team-correction`);`time-context` / `runtime-context` / `skill-catalog` / `subagent-settled` 等宿主
|
|
28
|
+
记账不算意图。激活提示词开头的成员身份段(「你是 X(角色)。你的个性与工作方式:…」)剥掉再挖——未剥时
|
|
29
|
+
il2c 16 个任务里 6 个是个性描述。助手只收 `text`(`reasoning` 不进摘要),工具只记名字不抄参数;上次
|
|
30
|
+
采集之后未写过的日志不解码;正在写的会话末尾半帧安全跳过(逐帧解码,整流解码会连带丢掉同块已解出的帧)。
|
|
31
|
+
zstd 由 Node 解码(`dsh_decode.mjs`;Python 3.11 标准库无 zstd),Node 取 `dsh_node` 配置 / `DSH_NODE` /
|
|
32
|
+
PATH(DSH 自带 `resources/runtime/primary-runtime/dependencies/node/bin/node.exe`);会话目录取 `dsh_home` /
|
|
33
|
+
`DSH_HOME` / `~/.dsh`。实测 il2c 最近 72 小时:只读 `harvest --source dsh` 18 秒挖出 13 个任务;
|
|
34
|
+
- **schtasks 输出按控制台代码页解码**:UTF-8 模式下(`-X utf8`)`text=True` 把 CP936 输出按 UTF-8 解,
|
|
35
|
+
读线程抛 `UnicodeDecodeError`、`stdout` 为 `None`,「列出已排程的项目」静默返回空。三处调用改走
|
|
36
|
+
`_run_schtasks`(OEM 代码页 + `errors="replace"`);
|
|
37
|
+
- 打包:`files` 补 `lib/vendor/skillopt/skillopt_sleep/**/*.mjs`(`lib/**/*.js` 不含 `.mjs`);
|
|
38
|
+
- 测试:新增 `test/skillopt-dsh-source.test.js`(多帧 zstd + 半帧尾、项目匹配、注入与推理过滤、身份段剥离、
|
|
39
|
+
按修改时间跳过、CLI 接受 `dsh`、schtasks UTF-8 模式);
|
|
40
|
+
|
|
41
|
+
## 0.4.102 - 2026-11-16
|
|
42
|
+
|
|
43
|
+
**DSH Desktop 侧边栏缺「文渊阁」入口(#26)**
|
|
44
|
+
|
|
45
|
+
- `package.json` 的 `exports` 补上 `"./package.json"`。DSH Desktop 宿主没有 `loader.internal` 时,
|
|
46
|
+
`dsh-client-modules` 的 `locatePkgJson` 走 CJS 回退 `createRequire(baseUrl).resolve('<pkg>/package.json')`;
|
|
47
|
+
本包未导出该子路径 → `ERR_PACKAGE_PATH_NOT_EXPORTED` 被 `catch {}` 吞掉 → 客户端行静默丢弃,宿主半边照常,
|
|
48
|
+
只是侧边栏没有入口。CLI 宿主走 `loader.internal.resolveSync`,不受影响。
|
|
49
|
+
- 测试:`test/manifest-locate.test.js` 用同一回退调用解析 manifest 与 `./client`(修复前 `ERR_PACKAGE_PATH_NOT_EXPORTED`)。
|
|
50
|
+
`node --test` 345 pass / 1 skip。
|
|
51
|
+
- E2E(独立 `DSH_HOME`,dsh CLI 新建 profile 装包):rc.1 / rc.2 / rc.3 上照搬回退分支判定,0.4.99 全部 `dropped`、
|
|
52
|
+
0.4.100 全部 `kept`;三个宿主带会话 cookie 启动,health 回读 0.4.100,页面清单含 `dsh-ai-team/client.js`,无 client-modules 报错。
|
|
53
|
+
|
|
3
54
|
## 0.4.101 - 2026-11-16
|
|
4
55
|
|
|
5
56
|
**团队推进:不等钟点、不提前收兵、个性不膨胀、夜间环真跑**
|
|
@@ -15,7 +15,7 @@ Common flags:
|
|
|
15
15
|
--target-skill-path PATH explicit live SKILL.md to stage/adopt
|
|
16
16
|
--tasks-file PATH reviewed TaskRecord JSON file to replay instead of harvesting
|
|
17
17
|
--backend mock|claude|codex|copilot|cursor|pi|opencode|handoff|azure_openai
|
|
18
|
-
--source claude|codex|copilot|copilot_cli|cursor|pi|opencode|auto
|
|
18
|
+
--source claude|codex|copilot|copilot_cli|cursor|pi|opencode|dsh|auto
|
|
19
19
|
--vscode-workspace-storage PATH
|
|
20
20
|
--copilot-cli-session-store PATH
|
|
21
21
|
--opencode-db PATH
|
|
@@ -117,7 +117,7 @@ def _add_common(p: argparse.ArgumentParser) -> None:
|
|
|
117
117
|
p.add_argument("--cursor-home", default="", help="override ~/.cursor for Cursor session harvest")
|
|
118
118
|
p.add_argument("--pi-home", default="", help="override ~/.pi for Pi session harvest")
|
|
119
119
|
p.add_argument("--source", default="",
|
|
120
|
-
choices=["", "claude", "codex", "copilot", "copilot_cli", "cursor", "pi", "opencode", "auto"],
|
|
120
|
+
choices=["", "claude", "codex", "copilot", "copilot_cli", "cursor", "pi", "opencode", "dsh", "auto"],
|
|
121
121
|
help="session transcript source")
|
|
122
122
|
p.add_argument("--vscode-workspace-storage", default="",
|
|
123
123
|
help="override VS Code User/workspaceStorage root for copilot source")
|
|
@@ -480,6 +480,14 @@ def _handoff_mine_and_pin(cfg, args, backend, snapshot: str, dry: bool):
|
|
|
480
480
|
# branch, or every later run re-scans the same stale window.
|
|
481
481
|
state.set_last_harvest(project, started, source)
|
|
482
482
|
state.save()
|
|
483
|
+
# The digest pin only protects answers of an unfinished round; with
|
|
484
|
+
# no tasks there are none. A kept pin is replayed every later night
|
|
485
|
+
# instead of harvesting (il2c: an empty pin from one `auto` run made
|
|
486
|
+
# every `dsh` night report "no tasks mined" over 10 live sessions).
|
|
487
|
+
try:
|
|
488
|
+
os.remove(digests_path)
|
|
489
|
+
except OSError:
|
|
490
|
+
pass
|
|
483
491
|
return 0, None
|
|
484
492
|
payload = make_tasks_payload(
|
|
485
493
|
tasks,
|
|
@@ -34,6 +34,8 @@ DEFAULTS: Dict[str, Any] = {
|
|
|
34
34
|
"vscode_workspace_storage": "", # "" => auto-detect platform defaults
|
|
35
35
|
"copilot_cli_session_store": "", # "" => ~/.copilot/session-store.db
|
|
36
36
|
"opencode_db": "", # "" => OPENCODE_DB or the OpenCode XDG data path
|
|
37
|
+
"dsh_home": "", # "" => DSH_HOME or ~/.dsh (DeepSeek Harness sessions)
|
|
38
|
+
"dsh_node": "", # "" => DSH_NODE or `node` on PATH (decodes zstd session logs)
|
|
37
39
|
# Explicit sources also include copilot, copilot_cli, cursor, pi, and opencode.
|
|
38
40
|
# ``auto`` keeps the established Codex-then-Claude precedence.
|
|
39
41
|
"transcript_source": "claude",
|
|
@@ -150,6 +152,11 @@ class SleepConfig:
|
|
|
150
152
|
cursor_home = os.path.abspath(os.path.expanduser(str(self.data["cursor_home"])))
|
|
151
153
|
return os.path.join(cursor_home, "projects")
|
|
152
154
|
|
|
155
|
+
@property
|
|
156
|
+
def dsh_sessions_dir(self) -> str:
|
|
157
|
+
home = self.data.get("dsh_home", "") or os.environ.get("DSH_HOME", "") or "~/.dsh"
|
|
158
|
+
return os.path.join(os.path.abspath(os.path.expanduser(str(home))), "sessions")
|
|
159
|
+
|
|
153
160
|
@property
|
|
154
161
|
def copilot_cli_session_store(self) -> str:
|
|
155
162
|
value = self.data.get("copilot_cli_session_store", "") or ""
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// SkillOpt-Sleep — decode one DeepSeek Harness session log to stdout.
|
|
2
|
+
//
|
|
3
|
+
// DSH stores every session as `<DSH_HOME>/sessions/<key>/<id>/session.v4.jsonl.zstd`:
|
|
4
|
+
// JSONL compressed as a series of zstd frames (one per flush). The Python
|
|
5
|
+
// standard library has no zstd decoder before 3.14, while every DSH install
|
|
6
|
+
// ships a Node runtime whose zlib has one — so the `dsh` transcript source runs
|
|
7
|
+
// this script and parses the JSONL it streams.
|
|
8
|
+
//
|
|
9
|
+
// Frames are decoded one at a time and written as soon as each completes:
|
|
10
|
+
// * the reader can stop after the header line (first frame) of a session that
|
|
11
|
+
// belongs to another project;
|
|
12
|
+
// * a session still being written ends in a partial frame — everything before
|
|
13
|
+
// it is emitted, the torn tail is dropped (a whole-stream decoder discards the
|
|
14
|
+
// already-decoded output of the read chunk that holds the error).
|
|
15
|
+
// A frame-magic match inside compressed bytes is not a boundary: such a segment
|
|
16
|
+
// fails to decode alone and is carried into the next one.
|
|
17
|
+
//
|
|
18
|
+
// Usage: node dsh_decode.mjs <session.v4.jsonl.zstd>
|
|
19
|
+
// Exit codes: 0 ok · 2 Node without zstd · 3 torn/corrupt tail dropped · 4 unreadable file.
|
|
20
|
+
import { readFileSync, writeSync } from 'node:fs';
|
|
21
|
+
import { zstdDecompressSync } from 'node:zlib';
|
|
22
|
+
|
|
23
|
+
const MAGIC = Buffer.from([0x28, 0xb5, 0x2f, 0xfd]);
|
|
24
|
+
const [file] = process.argv.slice(2);
|
|
25
|
+
if (typeof zstdDecompressSync !== 'function') {
|
|
26
|
+
process.stderr.write(`dsh_decode: Node ${process.version} has no zstd support (needs >= 22.15)\n`);
|
|
27
|
+
process.exit(2);
|
|
28
|
+
}
|
|
29
|
+
let buffer;
|
|
30
|
+
try {
|
|
31
|
+
buffer = readFileSync(file);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
process.stderr.write(`dsh_decode: ${error?.message ?? error}\n`);
|
|
34
|
+
process.exit(4);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const starts = [];
|
|
38
|
+
for (let at = buffer.indexOf(MAGIC); at !== -1; at = buffer.indexOf(MAGIC, at + 4)) starts.push(at);
|
|
39
|
+
let carryFrom = null;
|
|
40
|
+
for (let i = 0; i < starts.length; i += 1) {
|
|
41
|
+
const from = carryFrom ?? starts[i];
|
|
42
|
+
const to = starts[i + 1] ?? buffer.length;
|
|
43
|
+
let text;
|
|
44
|
+
try {
|
|
45
|
+
text = zstdDecompressSync(buffer.subarray(from, to));
|
|
46
|
+
} catch {
|
|
47
|
+
carryFrom = from;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
carryFrom = null;
|
|
51
|
+
try {
|
|
52
|
+
writeSync(1, text);
|
|
53
|
+
} catch {
|
|
54
|
+
// The reader closed the pipe: it has what it needs.
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (carryFrom !== null) {
|
|
59
|
+
process.stderr.write('dsh_decode: torn or corrupt tail dropped\n');
|
|
60
|
+
process.exitCode = 3;
|
|
61
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""SkillOpt-Sleep — DeepSeek Harness (DSH) session harvesting.
|
|
2
|
+
|
|
3
|
+
DSH keeps one append-only event log per session at
|
|
4
|
+
``<DSH_HOME>/sessions/<key>/<sessionId>/session.v4.jsonl.zstd``. The JSONL is
|
|
5
|
+
zstd-compressed; it is decoded by ``dsh_decode.mjs`` under a Node runtime
|
|
6
|
+
(every DSH install ships one; Python's stdlib has no zstd before 3.14).
|
|
7
|
+
|
|
8
|
+
Schema (DSH session v4, ``packages/core/session/src/types.ts``):
|
|
9
|
+
* line 1 is the header: ``{"type": "session", "version": 4, "id", "createdAt",
|
|
10
|
+
"cwd", "parentSession"?, "origin"?}`` — ``cwd`` is the project the session
|
|
11
|
+
was opened in;
|
|
12
|
+
* every other line is ``{"type", "seq", "time" (epoch ms), "data"}``:
|
|
13
|
+
- ``user/message``: ``data.content`` blocks plus ``data.source.kind`` —
|
|
14
|
+
a human prompt or a host wake, or synthetic context (skill text,
|
|
15
|
+
reminders) under other kinds, which is not user intent;
|
|
16
|
+
- ``assistant/message``: ``data.message.content`` blocks — ``text`` is
|
|
17
|
+
kept, ``reasoning`` (private) is skipped;
|
|
18
|
+
- ``tool/call``: ``data.name`` (arguments are never copied).
|
|
19
|
+
|
|
20
|
+
AI-team member sessions are ordinary DSH sessions opened in the team's
|
|
21
|
+
workspace, so they match the invoked project like any other session.
|
|
22
|
+
|
|
23
|
+
This module performs NO writes and NO network calls.
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import json
|
|
28
|
+
import os
|
|
29
|
+
import re
|
|
30
|
+
import shutil
|
|
31
|
+
import subprocess
|
|
32
|
+
import time
|
|
33
|
+
from typing import Any, Iterator, List, Optional
|
|
34
|
+
|
|
35
|
+
from skillopt_sleep.harvest import (
|
|
36
|
+
_detect_feedback,
|
|
37
|
+
_is_headless_replay,
|
|
38
|
+
_is_meta_prompt,
|
|
39
|
+
_project_matches,
|
|
40
|
+
_text_from_content,
|
|
41
|
+
)
|
|
42
|
+
from skillopt_sleep.staging import redact_secrets
|
|
43
|
+
from skillopt_sleep.types import SessionDigest
|
|
44
|
+
|
|
45
|
+
SESSION_FILE = "session.v4.jsonl.zstd"
|
|
46
|
+
DECODER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "dsh_decode.mjs")
|
|
47
|
+
# ``user/message`` sources that carry intent (counted on il2c, 11-16: a member
|
|
48
|
+
# session holds 1 ``user`` prompt and 37 ``agent-message`` relays):
|
|
49
|
+
# * ``user`` — the human's own prompt;
|
|
50
|
+
# * ``agent-message`` — messages relayed from another session; AI-team task
|
|
51
|
+
# wakes reach members this way ("Agent lead sent a message: … Team event: …");
|
|
52
|
+
# * ``ai-team`` — the plugin's in-turn correction (e.g. an action deferred to a
|
|
53
|
+
# clock time); it is kept and also recorded as negative feedback, because it
|
|
54
|
+
# marks the preceding reply as the wrong way to work.
|
|
55
|
+
# Host bookkeeping (``time-context``, ``runtime-context``, ``skill-catalog``,
|
|
56
|
+
# ``agent-instructions``, ``subagent-settled``, ``tool-jobs``, …) is not intent.
|
|
57
|
+
_INTENT_SOURCES = {"", "user", "agent-message", "ai-team"}
|
|
58
|
+
_RELAY_PREFIX = re.compile(r"^Agent \S+ sent a message:\s*")
|
|
59
|
+
# AI-team activation prompts start with the member's identity block
|
|
60
|
+
# (``memberIdentity`` in lib/domain/member-profile.js: "你是 <名>(<角色>)。"
|
|
61
|
+
# plus personality / skills / notes lines, then a blank line, then the
|
|
62
|
+
# prompt). Mined as intent, the identity is what every member session "asks
|
|
63
|
+
# for" (il2c harvest, 11-16: 6 of 16 tasks were personalities). Only the part
|
|
64
|
+
# after the block is the request.
|
|
65
|
+
_IDENTITY_HEAD = re.compile(r"^你是 [^\n]+([^\n]*)。\n")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _strip_member_identity(text: str) -> str:
|
|
69
|
+
if not _IDENTITY_HEAD.match(text):
|
|
70
|
+
return text
|
|
71
|
+
_block, sep, rest = text.partition("\n\n")
|
|
72
|
+
return rest.strip() if sep else ""
|
|
73
|
+
# Host bookkeeping the loop delivers as user messages.
|
|
74
|
+
_HOST_NOISE = re.compile(
|
|
75
|
+
r"^(?:Time sampled while preparing turn|The working directory changed from|<system-reminder>)"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class DshSourceError(RuntimeError):
|
|
80
|
+
"""The DSH source cannot run (no usable Node runtime)."""
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def resolve_node(configured: str = "") -> str:
|
|
84
|
+
"""Node used to decode sessions: config ``dsh_node`` > ``DSH_NODE`` > PATH."""
|
|
85
|
+
for candidate in (configured, os.environ.get("DSH_NODE", "")):
|
|
86
|
+
if candidate:
|
|
87
|
+
return candidate
|
|
88
|
+
found = shutil.which("node")
|
|
89
|
+
if found:
|
|
90
|
+
return found
|
|
91
|
+
raise DshSourceError(
|
|
92
|
+
"transcript_source 'dsh' needs a Node runtime (>= 22.15) to decode DSH sessions: "
|
|
93
|
+
"set dsh_node in ~/.skillopt-sleep/config.json or DSH_NODE "
|
|
94
|
+
"(DSH ships one at <install>/resources/runtime/primary-runtime/dependencies/node/bin/node.exe)"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _iso_local(ms: Any) -> str:
|
|
99
|
+
if not isinstance(ms, (int, float)) or isinstance(ms, bool):
|
|
100
|
+
return ""
|
|
101
|
+
return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(ms / 1000.0))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _since_epoch(since_iso: Optional[str]) -> Optional[float]:
|
|
105
|
+
if not since_iso:
|
|
106
|
+
return None
|
|
107
|
+
try:
|
|
108
|
+
return time.mktime(time.strptime(since_iso[:19], "%Y-%m-%dT%H:%M:%S"))
|
|
109
|
+
except (ValueError, OverflowError):
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _decoded_lines(node: str, path: str) -> Iterator[dict]:
|
|
114
|
+
"""Stream the session's JSON records; closing the generator stops Node."""
|
|
115
|
+
proc = subprocess.Popen(
|
|
116
|
+
[node, DECODER, path],
|
|
117
|
+
stdout=subprocess.PIPE,
|
|
118
|
+
stderr=subprocess.DEVNULL,
|
|
119
|
+
)
|
|
120
|
+
try:
|
|
121
|
+
assert proc.stdout is not None
|
|
122
|
+
for raw in proc.stdout:
|
|
123
|
+
raw = raw.strip()
|
|
124
|
+
if not raw:
|
|
125
|
+
continue
|
|
126
|
+
try:
|
|
127
|
+
record = json.loads(raw.decode("utf-8"))
|
|
128
|
+
except (UnicodeDecodeError, ValueError):
|
|
129
|
+
# A session still being written ends in a partial line.
|
|
130
|
+
continue
|
|
131
|
+
if isinstance(record, dict):
|
|
132
|
+
yield record
|
|
133
|
+
finally:
|
|
134
|
+
if proc.poll() is None:
|
|
135
|
+
proc.kill()
|
|
136
|
+
if proc.stdout is not None:
|
|
137
|
+
proc.stdout.close()
|
|
138
|
+
proc.wait()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _dedup(xs: List[str]) -> List[str]:
|
|
142
|
+
seen: set = set()
|
|
143
|
+
out: List[str] = []
|
|
144
|
+
for x in xs:
|
|
145
|
+
if x not in seen:
|
|
146
|
+
seen.add(x)
|
|
147
|
+
out.append(x)
|
|
148
|
+
return out
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def digest_dsh_session(path: str, *, node: str, project: str = "") -> Optional[SessionDigest]:
|
|
152
|
+
"""Build a :class:`SessionDigest` from one DSH session log.
|
|
153
|
+
|
|
154
|
+
With ``project`` set, the header's ``cwd`` is checked first and the rest of
|
|
155
|
+
the log is never decoded for sessions of other projects.
|
|
156
|
+
"""
|
|
157
|
+
records = _decoded_lines(node, path)
|
|
158
|
+
try:
|
|
159
|
+
header = next(records, None)
|
|
160
|
+
if not isinstance(header, dict) or header.get("type") != "session":
|
|
161
|
+
return None
|
|
162
|
+
cwd = header.get("cwd") if isinstance(header.get("cwd"), str) else ""
|
|
163
|
+
# An empty cwd would resolve against the engine's own working directory.
|
|
164
|
+
if project and (not cwd or not _project_matches(cwd, "invoked", project)):
|
|
165
|
+
return None
|
|
166
|
+
session_id = str(header.get("id") or os.path.basename(os.path.dirname(path)))
|
|
167
|
+
started = _iso_local(header.get("createdAt"))
|
|
168
|
+
ended = started
|
|
169
|
+
user_prompts: List[str] = []
|
|
170
|
+
assistant_finals: List[str] = []
|
|
171
|
+
tools: List[str] = []
|
|
172
|
+
feedback: List[str] = []
|
|
173
|
+
n_user = 0
|
|
174
|
+
n_asst = 0
|
|
175
|
+
for rec in records:
|
|
176
|
+
stamp = _iso_local(rec.get("time"))
|
|
177
|
+
if stamp:
|
|
178
|
+
ended = stamp
|
|
179
|
+
rtype = rec.get("type")
|
|
180
|
+
data = rec.get("data") if isinstance(rec.get("data"), dict) else {}
|
|
181
|
+
if rtype == "user/message":
|
|
182
|
+
source = data.get("source") if isinstance(data.get("source"), dict) else {}
|
|
183
|
+
kind = str(source.get("kind") or "")
|
|
184
|
+
if kind not in _INTENT_SOURCES:
|
|
185
|
+
continue
|
|
186
|
+
text = str(redact_secrets(_text_from_content(data.get("content")))).strip()
|
|
187
|
+
if kind == "agent-message":
|
|
188
|
+
text = _RELAY_PREFIX.sub("", text, count=1)
|
|
189
|
+
text = _strip_member_identity(text)
|
|
190
|
+
if not text or _HOST_NOISE.match(text) or _is_meta_prompt(text):
|
|
191
|
+
continue
|
|
192
|
+
n_user += 1
|
|
193
|
+
user_prompts.append(text)
|
|
194
|
+
feedback.extend(_detect_feedback(text))
|
|
195
|
+
if kind == "ai-team":
|
|
196
|
+
feedback.append("neg:ai-team-correction")
|
|
197
|
+
elif rtype == "assistant/message":
|
|
198
|
+
message = data.get("message") if isinstance(data.get("message"), dict) else {}
|
|
199
|
+
n_asst += 1
|
|
200
|
+
text = _text_from_content(message.get("content")).strip()
|
|
201
|
+
if text:
|
|
202
|
+
assistant_finals.append(str(redact_secrets(text)).strip())
|
|
203
|
+
elif rtype == "tool/call":
|
|
204
|
+
name = data.get("name")
|
|
205
|
+
if isinstance(name, str) and name:
|
|
206
|
+
tools.append(re.sub(r"[^A-Za-z0-9_.:-]+", "_", name)[:80])
|
|
207
|
+
finally:
|
|
208
|
+
records.close()
|
|
209
|
+
|
|
210
|
+
if n_user == 0 and n_asst == 0:
|
|
211
|
+
return None
|
|
212
|
+
digest = SessionDigest(
|
|
213
|
+
session_id=session_id,
|
|
214
|
+
project=cwd,
|
|
215
|
+
started_at=started,
|
|
216
|
+
ended_at=ended,
|
|
217
|
+
user_prompts=user_prompts,
|
|
218
|
+
assistant_finals=assistant_finals[-5:],
|
|
219
|
+
tools_used=_dedup(tools),
|
|
220
|
+
files_touched=[],
|
|
221
|
+
feedback_signals=_dedup(feedback),
|
|
222
|
+
n_user_turns=n_user,
|
|
223
|
+
n_assistant_turns=n_asst,
|
|
224
|
+
raw_path=path,
|
|
225
|
+
)
|
|
226
|
+
if _is_headless_replay(digest):
|
|
227
|
+
return None
|
|
228
|
+
return digest
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def harvest_dsh(
|
|
232
|
+
sessions_dir: str,
|
|
233
|
+
*,
|
|
234
|
+
node: str = "",
|
|
235
|
+
scope: Any = "all",
|
|
236
|
+
invoked_project: str = "",
|
|
237
|
+
since_iso: Optional[str] = None,
|
|
238
|
+
limit: int = 0,
|
|
239
|
+
) -> List[SessionDigest]:
|
|
240
|
+
"""Walk ``<DSH_HOME>/sessions`` (newest first) and return digests.
|
|
241
|
+
|
|
242
|
+
Parameters mirror :func:`skillopt_sleep.harvest.harvest`. Sessions whose log
|
|
243
|
+
has not been written since ``since_iso`` are skipped without decoding.
|
|
244
|
+
"""
|
|
245
|
+
digests: List[SessionDigest] = []
|
|
246
|
+
if not os.path.isdir(sessions_dir):
|
|
247
|
+
return digests
|
|
248
|
+
node = resolve_node(node)
|
|
249
|
+
since = _since_epoch(since_iso)
|
|
250
|
+
|
|
251
|
+
paths: List[tuple[float, str]] = []
|
|
252
|
+
for key in os.listdir(sessions_dir):
|
|
253
|
+
key_dir = os.path.join(sessions_dir, key)
|
|
254
|
+
if not os.path.isdir(key_dir):
|
|
255
|
+
continue
|
|
256
|
+
for session in os.listdir(key_dir):
|
|
257
|
+
path = os.path.join(key_dir, session, SESSION_FILE)
|
|
258
|
+
try:
|
|
259
|
+
mtime = os.path.getmtime(path)
|
|
260
|
+
except OSError:
|
|
261
|
+
continue
|
|
262
|
+
if since is not None and mtime < since:
|
|
263
|
+
continue
|
|
264
|
+
paths.append((mtime, path))
|
|
265
|
+
paths.sort(key=lambda item: item[0], reverse=True)
|
|
266
|
+
|
|
267
|
+
project_hint = invoked_project if scope == "invoked" else ""
|
|
268
|
+
for _mtime, path in paths:
|
|
269
|
+
digest = digest_dsh_session(path, node=node, project=project_hint)
|
|
270
|
+
if digest is None:
|
|
271
|
+
continue
|
|
272
|
+
if not _project_matches(digest.project or "", scope, invoked_project):
|
|
273
|
+
continue
|
|
274
|
+
if since_iso and digest.ended_at and digest.ended_at < since_iso:
|
|
275
|
+
continue
|
|
276
|
+
digests.append(digest)
|
|
277
|
+
if limit and len(digests) >= limit:
|
|
278
|
+
break
|
|
279
|
+
return digests
|
|
@@ -8,6 +8,7 @@ from skillopt_sleep.harvest_codex import harvest_codex
|
|
|
8
8
|
from skillopt_sleep.harvest_copilot import harvest_copilot
|
|
9
9
|
from skillopt_sleep.harvest_copilot_cli import harvest_copilot_cli
|
|
10
10
|
from skillopt_sleep.harvest_cursor import harvest_cursor
|
|
11
|
+
from skillopt_sleep.harvest_dsh import harvest_dsh
|
|
11
12
|
from skillopt_sleep.harvest_opencode import harvest_opencode
|
|
12
13
|
from skillopt_sleep.harvest_pi import harvest_pi
|
|
13
14
|
from skillopt_sleep.types import SessionDigest
|
|
@@ -20,6 +21,7 @@ SUPPORTED_SOURCES = (
|
|
|
20
21
|
"cursor",
|
|
21
22
|
"pi",
|
|
22
23
|
"opencode",
|
|
24
|
+
"dsh",
|
|
23
25
|
"auto",
|
|
24
26
|
)
|
|
25
27
|
|
|
@@ -114,6 +116,15 @@ def harvest_for_config(
|
|
|
114
116
|
since_iso=since_iso,
|
|
115
117
|
limit=limit,
|
|
116
118
|
)
|
|
119
|
+
if source == "dsh":
|
|
120
|
+
return harvest_dsh(
|
|
121
|
+
cfg.dsh_sessions_dir,
|
|
122
|
+
node=cfg.get("dsh_node", "") or "",
|
|
123
|
+
scope=scope,
|
|
124
|
+
invoked_project=invoked_project,
|
|
125
|
+
since_iso=since_iso,
|
|
126
|
+
limit=limit,
|
|
127
|
+
)
|
|
117
128
|
if source == "auto":
|
|
118
129
|
codex_digests = harvest_codex(
|
|
119
130
|
cfg.codex_archived_sessions_dir,
|
|
@@ -65,11 +65,37 @@ def _win_task_name(project: str) -> str:
|
|
|
65
65
|
return f"SkillOpt-Sleep-{digest}"
|
|
66
66
|
|
|
67
67
|
|
|
68
|
+
def _console_encoding() -> str:
|
|
69
|
+
"""The code page schtasks.exe writes its output in.
|
|
70
|
+
|
|
71
|
+
schtasks prints in the console OEM code page (CP936 on a Chinese system),
|
|
72
|
+
not in Python's preferred encoding. Under UTF-8 mode (``-X utf8`` /
|
|
73
|
+
``PYTHONUTF8=1``) ``text=True`` decoded that output as UTF-8: the reader
|
|
74
|
+
thread raised UnicodeDecodeError and ``proc.stdout`` came back ``None``, so
|
|
75
|
+
``_list_win_tasks`` silently listed nothing.
|
|
76
|
+
"""
|
|
77
|
+
try:
|
|
78
|
+
import ctypes
|
|
79
|
+
|
|
80
|
+
return f"cp{ctypes.windll.kernel32.GetOEMCP()}"
|
|
81
|
+
except Exception:
|
|
82
|
+
return "mbcs" if sys.platform == "win32" else "utf-8"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _run_schtasks(args: List[str]) -> subprocess.CompletedProcess:
|
|
86
|
+
return subprocess.run(
|
|
87
|
+
["schtasks", *args],
|
|
88
|
+
capture_output=True,
|
|
89
|
+
text=True,
|
|
90
|
+
encoding=_console_encoding(),
|
|
91
|
+
errors="replace",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
68
95
|
def _create_win_task(task_name: str, command: str, hour: int, minute: int) -> bool:
|
|
69
96
|
try:
|
|
70
97
|
st = f"{hour:02d}:{minute:02d}"
|
|
71
|
-
|
|
72
|
-
proc = subprocess.run(cmd, capture_output=True, text=True)
|
|
98
|
+
proc = _run_schtasks(["/create", "/tn", task_name, "/tr", command, "/sc", "daily", "/st", st, "/f"])
|
|
73
99
|
return proc.returncode == 0
|
|
74
100
|
except Exception:
|
|
75
101
|
return False
|
|
@@ -77,28 +103,35 @@ def _create_win_task(task_name: str, command: str, hour: int, minute: int) -> bo
|
|
|
77
103
|
|
|
78
104
|
def _delete_win_task(task_name: str) -> bool:
|
|
79
105
|
try:
|
|
80
|
-
|
|
81
|
-
proc = subprocess.run(cmd, capture_output=True, text=True)
|
|
106
|
+
proc = _run_schtasks(["/delete", "/tn", task_name, "/f"])
|
|
82
107
|
return proc.returncode == 0
|
|
83
108
|
except Exception:
|
|
84
109
|
return False
|
|
85
110
|
|
|
86
111
|
|
|
112
|
+
def _parse_win_task_names(csv_text: str) -> List[str]:
|
|
113
|
+
"""SkillOpt task names from ``schtasks /query /fo csv`` output.
|
|
114
|
+
|
|
115
|
+
schtasks reports task paths (``"\\SkillOpt-Sleep-…"`` for a root-folder
|
|
116
|
+
task); matching the bare prefix against the path never found one, so the
|
|
117
|
+
listing was always empty even with tasks installed.
|
|
118
|
+
"""
|
|
119
|
+
tasks: List[str] = []
|
|
120
|
+
for line in csv_text.splitlines():
|
|
121
|
+
if not line.startswith('"'):
|
|
122
|
+
continue
|
|
123
|
+
name = line.split(",", 1)[0].strip('"').lstrip("\\")
|
|
124
|
+
if name.startswith("SkillOpt-Sleep-") and name not in tasks:
|
|
125
|
+
tasks.append(name)
|
|
126
|
+
return tasks
|
|
127
|
+
|
|
128
|
+
|
|
87
129
|
def _list_win_tasks() -> List[str]:
|
|
88
130
|
try:
|
|
89
|
-
proc =
|
|
131
|
+
proc = _run_schtasks(["/query", "/fo", "csv"])
|
|
90
132
|
if proc.returncode != 0:
|
|
91
133
|
return []
|
|
92
|
-
|
|
93
|
-
for line in proc.stdout.splitlines():
|
|
94
|
-
if not line.startswith('"'):
|
|
95
|
-
continue
|
|
96
|
-
parts = line.split(",")
|
|
97
|
-
if len(parts) > 0:
|
|
98
|
-
name = parts[0].strip('"')
|
|
99
|
-
if name.startswith("SkillOpt-Sleep-"):
|
|
100
|
-
tasks.append(name)
|
|
101
|
-
return tasks
|
|
134
|
+
return _parse_win_task_names(proc.stdout or "")
|
|
102
135
|
except Exception:
|
|
103
136
|
return []
|
|
104
137
|
|
|
@@ -286,7 +286,7 @@ export function apply(ctx, config = {}) {
|
|
|
286
286
|
'Preview a full sleep cycle without staging anything: harvest, mine, replay, report.',
|
|
287
287
|
parameters: {
|
|
288
288
|
project: { type: 'string', description: 'Project directory' },
|
|
289
|
-
source: { type: 'string', description: 'Transcript source: claude|codex|copilot|cursor|pi|opencode|auto' },
|
|
289
|
+
source: { type: 'string', description: 'Transcript source: claude|codex|copilot|cursor|pi|opencode|dsh|auto (dsh = DeepSeek Harness sessions, incl. AI-team members)' },
|
|
290
290
|
backend: { type: 'string', description: 'Backend: mock|claude|codex|copilot|cursor|pi|opencode|handoff|azure_openai' },
|
|
291
291
|
model: { type: 'string', description: 'Backend model override' },
|
|
292
292
|
maxTasks: { type: 'number', description: 'Cap mined tasks (default 40)' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.104",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"exports": {
|
|
31
31
|
".": "./index.js",
|
|
32
32
|
"./client": "./client.js",
|
|
33
|
+
"./package.json": "./package.json",
|
|
33
34
|
"./lib/*": "./lib/*",
|
|
34
35
|
"./locale/*.json": "./locale/*.json",
|
|
35
36
|
"./icon": "./icon.svg"
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"lib/**/*.js",
|
|
47
48
|
"lib/vendor/skillopt/scripts/*.py",
|
|
48
49
|
"lib/vendor/skillopt/skillopt_sleep/**/*.py",
|
|
50
|
+
"lib/vendor/skillopt/skillopt_sleep/**/*.mjs",
|
|
49
51
|
"lib/vendor/skillopt/requirements.txt",
|
|
50
52
|
"lib/vendor/skillopt/LICENSE",
|
|
51
53
|
"skills/**/*",
|
|
@@ -77,7 +77,7 @@ night can still fail every night.
|
|
|
77
77
|
|---|---|---|
|
|
78
78
|
| `project` | config or cwd | project directory to evolve |
|
|
79
79
|
| `backend` | `mock` | `mock\|claude\|codex\|copilot\|cursor\|pi\|opencode\|handoff\|azure_openai` (mock = no model calls) |
|
|
80
|
-
| `source` | config | transcript source: `claude\|codex\|copilot\|cursor\|pi\|opencode\|auto` |
|
|
80
|
+
| `source` | config | transcript source: `claude\|codex\|copilot\|cursor\|pi\|opencode\|dsh\|auto` — `dsh` reads DeepSeek Harness sessions (AI-team members included) whose working directory is the project; schedule it with `project=<workspace>` |
|
|
81
81
|
| `model` | backend default | replay model override |
|
|
82
82
|
| `maxTasks` | 40 | mined-task cap |
|
|
83
83
|
| `preferences` | empty | house rules for the reflection prior (e.g. "always use async/await") |
|