@suifei/dsh-ai-team 0.0.0-stage → 0.3.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 +98 -0
- package/LICENSE +21 -0
- package/README.md +38 -2
- package/client.js +2901 -0
- package/cordis.patch.yml +31 -0
- package/icon.svg +27 -0
- package/index.js +893 -0
- package/lib/domain/errors.js +36 -0
- package/lib/domain/ids.js +26 -0
- package/lib/domain/inbox.js +87 -0
- package/lib/domain/member-config.js +168 -0
- package/lib/domain/member-profile.js +53 -0
- package/lib/domain/policy.js +102 -0
- package/lib/domain/task.js +309 -0
- package/lib/domain/thread.js +54 -0
- package/lib/host/fault-adapter.js +50 -0
- package/lib/host/member-tools.js +225 -0
- package/lib/host/permission-guard.js +28 -0
- package/lib/host/project-registry.js +68 -0
- package/lib/host/project-runtime.js +73 -0
- package/lib/host/service.js +810 -0
- package/lib/host/views.js +213 -0
- package/lib/host/waker.js +177 -0
- package/lib/ledger/checkpoint.js +395 -0
- package/lib/ledger/events.js +398 -0
- package/lib/ledger/fold.js +991 -0
- package/lib/ledger/writer.js +983 -0
- package/lib/runtime/failure-policy.js +113 -0
- package/lib/runtime/host-agent.js +101 -0
- package/lib/runtime/member-runtime.js +286 -0
- package/lib/runtime/skill-catalog.js +27 -0
- package/lib/runtime/skill-loader.js +26 -0
- package/lib/runtime/skill-provider.js +121 -0
- package/lib/vendor/skillopt/LICENSE +21 -0
- package/lib/vendor/skillopt/requirements.txt +31 -0
- package/lib/vendor/skillopt/scripts/sleep.py +119 -0
- package/lib/vendor/skillopt/skillopt_sleep/__init__.py +20 -0
- package/lib/vendor/skillopt/skillopt_sleep/__main__.py +942 -0
- package/lib/vendor/skillopt/skillopt_sleep/adapters/__init__.py +1 -0
- package/lib/vendor/skillopt/skillopt_sleep/adapters/superpowers.py +1379 -0
- package/lib/vendor/skillopt/skillopt_sleep/backend.py +2844 -0
- package/lib/vendor/skillopt/skillopt_sleep/budget.py +75 -0
- package/lib/vendor/skillopt/skillopt_sleep/config.py +257 -0
- package/lib/vendor/skillopt/skillopt_sleep/consolidate.py +558 -0
- package/lib/vendor/skillopt/skillopt_sleep/cycle.py +1270 -0
- package/lib/vendor/skillopt/skillopt_sleep/dream.py +173 -0
- package/lib/vendor/skillopt/skillopt_sleep/evalkit.py +718 -0
- package/lib/vendor/skillopt/skillopt_sleep/evidence.py +143 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/__init__.py +1 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/gbrain_bench.py +119 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/personas.py +86 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/report.py +132 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/run_experiment.py +178 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/run_gbrain.py +209 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/run_transfer.py +155 -0
- package/lib/vendor/skillopt/skillopt_sleep/experiments/sweep.py +164 -0
- package/lib/vendor/skillopt/skillopt_sleep/gate.py +50 -0
- package/lib/vendor/skillopt/skillopt_sleep/handoff_backend.py +173 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest.py +691 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_codex.py +260 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_copilot.py +443 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_copilot_cli.py +244 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_cursor.py +316 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_opencode.py +364 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_pi.py +311 -0
- package/lib/vendor/skillopt/skillopt_sleep/harvest_sources.py +135 -0
- package/lib/vendor/skillopt/skillopt_sleep/judges.py +344 -0
- package/lib/vendor/skillopt/skillopt_sleep/llm_miner.py +187 -0
- package/lib/vendor/skillopt/skillopt_sleep/memory.py +166 -0
- package/lib/vendor/skillopt/skillopt_sleep/mine.py +427 -0
- package/lib/vendor/skillopt/skillopt_sleep/multi_skill.py +190 -0
- package/lib/vendor/skillopt/skillopt_sleep/prompts.py +250 -0
- package/lib/vendor/skillopt/skillopt_sleep/replay.py +211 -0
- package/lib/vendor/skillopt/skillopt_sleep/rollout.py +184 -0
- package/lib/vendor/skillopt/skillopt_sleep/scheduler.py +286 -0
- package/lib/vendor/skillopt/skillopt_sleep/skill_resolver.py +244 -0
- package/lib/vendor/skillopt/skillopt_sleep/slow_update.py +141 -0
- package/lib/vendor/skillopt/skillopt_sleep/staging.py +3285 -0
- package/lib/vendor/skillopt/skillopt_sleep/state.py +283 -0
- package/lib/vendor/skillopt/skillopt_sleep/tasks_file.py +100 -0
- package/lib/vendor/skillopt/skillopt_sleep/types.py +227 -0
- package/lib/vendor/skillopt/src/index.js +394 -0
- package/package.json +62 -4
- package/skills/skillopt-sleep/SKILL.md +121 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// dsh-skillopt — Microsoft SkillOpt-Sleep integration for DeepSeek Harness.
|
|
2
|
+
//
|
|
3
|
+
// Gives the dsh agent a "sleep cycle": harvest past sessions -> mine recurring
|
|
4
|
+
// tasks -> replay via a backend -> consolidate validated skills behind a
|
|
5
|
+
// held-out gate. The heavy lifting is done by the upstream `skillopt_sleep`
|
|
6
|
+
// Python engine (https://github.com/microsoft/SkillOpt); this plugin exposes
|
|
7
|
+
// it to the agent as native dsh tools, plus a skill and configuration.
|
|
8
|
+
|
|
9
|
+
const defineTool = (definition) => definition
|
|
10
|
+
import { dirname, join } from 'node:path'
|
|
11
|
+
import { fileURLToPath } from 'node:url'
|
|
12
|
+
|
|
13
|
+
export const name = 'skillopt'
|
|
14
|
+
|
|
15
|
+
// Plugin directory (absolute) — used to resolve the bundled engine script so
|
|
16
|
+
// it works regardless of the dsh process cwd.
|
|
17
|
+
const PLUGIN_DIR = dirname(fileURLToPath(import.meta.url)) + '/..'
|
|
18
|
+
|
|
19
|
+
// Exported for the canary test (scripts/canary.mjs).
|
|
20
|
+
export { buildArgv, quoteArgv, q, IS_WINDOWS }
|
|
21
|
+
|
|
22
|
+
// Wait for the tool registry and the shell executor before applying.
|
|
23
|
+
export const inject = ['tools', 'shell']
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Config (Schemastery)
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Helpers
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
// Quote one argv element for the HOST's shell. dsh's ctx.shell is the
|
|
34
|
+
// platform executor: on win32 the bash stack is disabled and ctx.shell is a
|
|
35
|
+
// pwsh executor (`pwsh -Command <one argv>`), on POSIX it is bash (`bash -c
|
|
36
|
+
// <one argv>`). PowerShell and POSIX shell quoting differ, so the quoting
|
|
37
|
+
// follows the platform:
|
|
38
|
+
//
|
|
39
|
+
// - POSIX (bash): single quotes are literal; an embedded single quote is
|
|
40
|
+
// expressed as '\'' (close quote, escaped quote, reopen quote) — the only
|
|
41
|
+
// portable POSIX spelling.
|
|
42
|
+
// - Windows (pwsh): single-quoted strings are literal too, but an embedded
|
|
43
|
+
// single quote is expressed as '' (doubled quote).
|
|
44
|
+
//
|
|
45
|
+
// Control characters are stripped as defense in depth: \r and \r\n inside a
|
|
46
|
+
// quoted word would otherwise split the value into multiple argv words
|
|
47
|
+
// (broken command, not RCE — quotes never execute), and \n would corrupt the
|
|
48
|
+
// engine's own arg parsing. Model-controlled values must arrive as exactly
|
|
49
|
+
// one argument under either shell.
|
|
50
|
+
const IS_WINDOWS = process.platform === 'win32'
|
|
51
|
+
|
|
52
|
+
function q(value) {
|
|
53
|
+
// Fold \r\n and lone \r into ONE space (not two), then strip remaining C0.
|
|
54
|
+
const s = String(value)
|
|
55
|
+
.replace(/\r\n?/g, ' ')
|
|
56
|
+
.replace(/[\n\u0000-\u001f\u007f]/g, ' ')
|
|
57
|
+
return IS_WINDOWS ? `'${s.replace(/'/g, "''")}'` : `'${s.replace(/'/g, "'\\''")}'`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Build the argv array for the engine with config defaults and per-call
|
|
62
|
+
* overrides. Returns an ARRAY (not a joined string); execute() quotes each
|
|
63
|
+
* element and lets shell.resolve() apply workdir/output-cap/sandbox defaults.
|
|
64
|
+
*
|
|
65
|
+
* The engine is invoked through scripts/sleep.py, which mirrors the official
|
|
66
|
+
* SkillOpt runner: it resolves a source checkout (repo root), picks a
|
|
67
|
+
* Python >= 3.10, and falls back to the `skillopt-sleep` CLI or an installed
|
|
68
|
+
* package. `config.module` still works as a direct `python -m <module>` escape
|
|
69
|
+
* hatch for users who prefer it.
|
|
70
|
+
*/
|
|
71
|
+
function buildArgv(config, action, explicit = {}, extras = [], allowed = null) {
|
|
72
|
+
const parts = [config.pythonCmd || 'python']
|
|
73
|
+
if (config.module) {
|
|
74
|
+
// explicit escape hatch: python -m <module>
|
|
75
|
+
parts.push('-m', config.module)
|
|
76
|
+
} else {
|
|
77
|
+
// default: the bundled bootstrap mirrors the official runner; resolve it
|
|
78
|
+
// absolutely so it works no matter what cwd dsh was started from.
|
|
79
|
+
parts.push(config.engineScript || join(PLUGIN_DIR, 'scripts', 'sleep.py'))
|
|
80
|
+
}
|
|
81
|
+
parts.push(action)
|
|
82
|
+
const push = (flag, value) => {
|
|
83
|
+
if (value !== undefined && value !== null && value !== '') parts.push(flag, String(value))
|
|
84
|
+
}
|
|
85
|
+
const has = (v) => v !== undefined && v !== null && v !== ''
|
|
86
|
+
// `allowed` is the tool's declared parameter set (null = everything, the
|
|
87
|
+
// pre-whitelist behavior). Both the model-supplied value AND the operator
|
|
88
|
+
// config default are gated on it, so a tool like skillopt_adopt (declares
|
|
89
|
+
// only `project`) never receives --backend/--model/--json/… from either
|
|
90
|
+
// source — the config default must not leak into tools that do not declare
|
|
91
|
+
// the key.
|
|
92
|
+
const permits = (key) => !allowed || allowed.includes(key)
|
|
93
|
+
const withDefault = (key, flag) => {
|
|
94
|
+
if (!permits(key)) return
|
|
95
|
+
if (has(explicit[key])) push(flag, explicit[key])
|
|
96
|
+
else push(flag, config[key])
|
|
97
|
+
}
|
|
98
|
+
withDefault('project', '--project')
|
|
99
|
+
withDefault('scope', '--scope')
|
|
100
|
+
withDefault('source', '--source')
|
|
101
|
+
withDefault('backend', '--backend')
|
|
102
|
+
withDefault('model', '--model')
|
|
103
|
+
withDefault('maxTasks', '--max-tasks')
|
|
104
|
+
withDefault('maxSessions', '--max-sessions')
|
|
105
|
+
withDefault('editBudget', '--edit-budget')
|
|
106
|
+
withDefault('preferences', '--preferences')
|
|
107
|
+
if (permits('json') && (config.jsonOutput || explicit.json)) parts.push('--json')
|
|
108
|
+
parts.push(...extras)
|
|
109
|
+
return parts
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Join argv with safe quoting for the platform shell. */
|
|
113
|
+
function quoteArgv(argv) {
|
|
114
|
+
const quoted = argv.map(q).join(' ')
|
|
115
|
+
// Windows PowerShell: a bare string is not a command invocation — `'python'
|
|
116
|
+
// 'args'` parses as a string-array expression and errors. Prepend the `&`
|
|
117
|
+
// call operator so the quoted argv runs as a command (same as bash, where
|
|
118
|
+
// the quote is the whole word and the first word is the command).
|
|
119
|
+
return IS_WINDOWS ? `& ${quoted}` : quoted
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Run one resolved spec on the host shell executor.
|
|
124
|
+
*
|
|
125
|
+
* dsh 0.2.x: `shell.execute(spec)` returns a ShellExecution; the foreground
|
|
126
|
+
* outcome is `await handle.result()`. dsh 0.1.x has only `shell.run(spec)`.
|
|
127
|
+
* plugins/dsh declares @deepseek-ai/dsh-tools for BOTH generations
|
|
128
|
+
* (`>=0.1.1-rc.2 <0.2.0 || >=0.2.0-rc.1 <0.3.0`), so the seam is detected
|
|
129
|
+
* instead of hard-switched — a hard switch breaks whichever side is older.
|
|
130
|
+
*/
|
|
131
|
+
export async function runShell(shell, spec) {
|
|
132
|
+
if (typeof shell.execute === 'function') return (await shell.execute(spec)).result()
|
|
133
|
+
return shell.run(spec)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Pick exactly the parameters a tool declares. dsh's parameter schema does
|
|
137
|
+
// not reject undeclared properties by default (no additionalProperties:false),
|
|
138
|
+
// so without this filter the model could inject fields (backend, model, json,
|
|
139
|
+
// editBudget, …) that buildArgv would forward to the engine — crossing the
|
|
140
|
+
// per-tool surface and, for skillopt_adopt, the live-change boundary. Each
|
|
141
|
+
// tool's build() must pass through exactly its declared keys.
|
|
142
|
+
function pick(obj, keys) {
|
|
143
|
+
const out = {}
|
|
144
|
+
for (const key of keys) {
|
|
145
|
+
if (obj[key] !== undefined) out[key] = obj[key]
|
|
146
|
+
}
|
|
147
|
+
return out
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Value-domain guard for model-supplied path-like strings.
|
|
151
|
+
//
|
|
152
|
+
// argv-level quoting (quoteArgv) protects the dsh `bash -c` boundary, but the
|
|
153
|
+
// engine re-interpolates these values into its OWN shell/command strings:
|
|
154
|
+
// scheduler.py builds `--project "{project}"` inside a crontab line and a
|
|
155
|
+
// Windows run.cmd executed by schtasks, and write_tasks_file() turns an
|
|
156
|
+
// arbitrary `output` into a file write (abspath + makedirs + overwrite). A
|
|
157
|
+
// model-controlled value containing `"`, `&`, `;`, `|`, `$`, backticks or
|
|
158
|
+
// other shell metacharacters would break out of that splice and execute as a
|
|
159
|
+
// separate command under the scheduler's shell, or overwrite an arbitrary
|
|
160
|
+
// file. Legitimate paths contain letters, digits, spaces, and `- _ . / \ :`
|
|
161
|
+
// only — reject everything else up front.
|
|
162
|
+
const UNSAFE_PATH = /["'&;|$`<>()\[\]{}*\u0000-\u001f\u007f]/
|
|
163
|
+
|
|
164
|
+
/** Throws on a path-like value carrying shell metacharacters. */
|
|
165
|
+
function assertSafePath(value, what) {
|
|
166
|
+
if (value === undefined || value === null || value === '') return
|
|
167
|
+
if (UNSAFE_PATH.test(String(value))) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`[skillopt] ${what} rejected: contains shell metacharacters (` +
|
|
170
|
+
`" ' & ; | $ \` < > ( ) [ ] { } * or control chars). ` +
|
|
171
|
+
`Use a plain directory/file path.`,
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Reject an output path that could write outside the working area:
|
|
178
|
+
* absolute paths and `..` traversal are refused; only a bare relative
|
|
179
|
+
* file name (or a simple relative path) is accepted.
|
|
180
|
+
*/
|
|
181
|
+
function assertSafeOutput(value) {
|
|
182
|
+
if (value === undefined || value === null || value === '') return
|
|
183
|
+
const s = String(value)
|
|
184
|
+
assertSafePath(s, 'output path')
|
|
185
|
+
if (s.startsWith('/') || s.startsWith('\\') || /^[A-Za-z]:[\\/]/.test(s) || s.includes('..')) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`[skillopt] output path rejected: absolute paths and ".." traversal are not allowed; ` +
|
|
188
|
+
`give a relative file name (e.g. "tasks.json").`,
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Range guard for schedule's clock parameters. The engine does not validate
|
|
195
|
+
* hour/minute itself and splices them straight into a crontab line and a
|
|
196
|
+
* schtasks start time; an out-of-range value (99, -1, …) would create a
|
|
197
|
+
* broken scheduled-task entry. Reject anything outside the real clock.
|
|
198
|
+
*/
|
|
199
|
+
function assertSafeClock(value, what, min, max) {
|
|
200
|
+
if (value === undefined || value === null || value === '') return
|
|
201
|
+
const n = Number(value)
|
|
202
|
+
if (!Number.isInteger(n) || n < min || n > max) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`[skillopt] ${what} rejected: must be an integer in [${min}, ${max}], got ${JSON.stringify(value)}.`,
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function renderOutput(_args, value) {
|
|
210
|
+
return [{ type: 'text', text: value }]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// Plugin entry
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
|
|
217
|
+
export function apply(ctx, config = {}) {
|
|
218
|
+
const shell = ctx.shell
|
|
219
|
+
|
|
220
|
+
const tools = [
|
|
221
|
+
{
|
|
222
|
+
name: 'skillopt_status',
|
|
223
|
+
description:
|
|
224
|
+
'Show SkillOpt-Sleep state: engine availability, latest staged proposal, last run report.',
|
|
225
|
+
parameters: {
|
|
226
|
+
project: { type: 'string', description: 'Project directory (defaults to config.project or cwd)' },
|
|
227
|
+
json: { type: 'boolean', description: 'Emit machine-readable JSON' },
|
|
228
|
+
},
|
|
229
|
+
build: (a) => buildArgv(config, 'status', pick(a, ['project', 'json']), [], ['project', 'json']),
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'skillopt_dry_run',
|
|
233
|
+
description:
|
|
234
|
+
'Preview a full sleep cycle without staging anything: harvest, mine, replay, report.',
|
|
235
|
+
parameters: {
|
|
236
|
+
project: { type: 'string', description: 'Project directory' },
|
|
237
|
+
source: { type: 'string', description: 'Transcript source: claude|codex|copilot|cursor|pi|opencode|auto' },
|
|
238
|
+
backend: { type: 'string', description: 'Backend: mock|claude|codex|copilot|cursor|pi|opencode|handoff|azure_openai' },
|
|
239
|
+
model: { type: 'string', description: 'Backend model override' },
|
|
240
|
+
maxTasks: { type: 'number', description: 'Cap mined tasks (default 40)' },
|
|
241
|
+
progress: { type: 'boolean', description: 'Print phase progress to stderr' },
|
|
242
|
+
},
|
|
243
|
+
build: (a) => buildArgv(config, 'dry-run', pick(a, ['project', 'source', 'backend', 'model', 'maxTasks']), a.progress ? ['--progress'] : [], ['project', 'source', 'backend', 'model', 'maxTasks']),
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: 'skillopt_run',
|
|
247
|
+
description:
|
|
248
|
+
'Run the full sleep cycle and stage a proposal. Nothing live changes until skillopt_adopt.',
|
|
249
|
+
parameters: {
|
|
250
|
+
project: { type: 'string', description: 'Project directory' },
|
|
251
|
+
backend: { type: 'string', description: 'Backend for model calls' },
|
|
252
|
+
source: { type: 'string', description: 'Transcript source' },
|
|
253
|
+
preferences: { type: 'string', description: 'House rules for the reflection prior' },
|
|
254
|
+
progress: { type: 'boolean', description: 'Print phase progress to stderr' },
|
|
255
|
+
},
|
|
256
|
+
build: (a) => {
|
|
257
|
+
const extra = []
|
|
258
|
+
// auto-adopt is OPERATOR-ONLY (config.autoAdopt); the model cannot set it.
|
|
259
|
+
if (config.autoAdopt) extra.push('--auto-adopt')
|
|
260
|
+
if (a.progress) extra.push('--progress')
|
|
261
|
+
return buildArgv(config, 'run', pick(a, ['project', 'backend', 'source', 'preferences']), extra, ['project', 'backend', 'source', 'preferences'])
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: 'skillopt_adopt',
|
|
266
|
+
description:
|
|
267
|
+
'Apply the latest staged proposal, backing up existing target files first. This is the live-change boundary.',
|
|
268
|
+
parameters: {
|
|
269
|
+
project: { type: 'string', description: 'Project directory' },
|
|
270
|
+
},
|
|
271
|
+
build: (a) => buildArgv(config, 'adopt', pick(a, ['project']), [], ['project']),
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: 'skillopt_harvest',
|
|
275
|
+
description:
|
|
276
|
+
'Harvest past sessions and show or export mined recurring tasks. Read-only.',
|
|
277
|
+
parameters: {
|
|
278
|
+
project: { type: 'string', description: 'Project directory' },
|
|
279
|
+
source: { type: 'string', description: 'Transcript source' },
|
|
280
|
+
output: { type: 'string', description: 'Export tasks JSON to this file' },
|
|
281
|
+
maxTasks: { type: 'number', description: 'Cap mined tasks' },
|
|
282
|
+
},
|
|
283
|
+
build: (a) => {
|
|
284
|
+
const extra = []
|
|
285
|
+
if (a.output) extra.push('--output', a.output)
|
|
286
|
+
return buildArgv(config, 'harvest', pick(a, ['project', 'source', 'maxTasks']), extra, ['project', 'source', 'maxTasks'])
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: 'skillopt_schedule',
|
|
291
|
+
description:
|
|
292
|
+
'Install a nightly cron entry that runs the sleep cycle for this project.',
|
|
293
|
+
parameters: {
|
|
294
|
+
project: { type: 'string', description: 'Project directory' },
|
|
295
|
+
hour: { type: 'number', description: 'Hour (0-23, default 3)' },
|
|
296
|
+
minute: { type: 'number', description: 'Minute (default 17)' },
|
|
297
|
+
backend: { type: 'string', description: 'Backend for scheduled runs' },
|
|
298
|
+
},
|
|
299
|
+
build: (a) => {
|
|
300
|
+
const extra = []
|
|
301
|
+
if (a.hour !== undefined) extra.push('--hour', String(a.hour))
|
|
302
|
+
if (a.minute !== undefined) extra.push('--minute', String(a.minute))
|
|
303
|
+
return buildArgv(config, 'schedule', pick(a, ['project', 'backend']), extra, ['project', 'backend'])
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: 'skillopt_unschedule',
|
|
308
|
+
description:
|
|
309
|
+
'Remove the nightly cron entry for this project.',
|
|
310
|
+
parameters: {
|
|
311
|
+
project: { type: 'string', description: 'Project directory' },
|
|
312
|
+
},
|
|
313
|
+
build: (a) => buildArgv(config, 'unschedule', pick(a, ['project']), config.unscheduleAll ? ['--all'] : [], ['project']),
|
|
314
|
+
},
|
|
315
|
+
]
|
|
316
|
+
|
|
317
|
+
const disposers = []
|
|
318
|
+
for (const t of tools) {
|
|
319
|
+
disposers.push(ctx.tools.register(
|
|
320
|
+
defineTool({
|
|
321
|
+
name: t.name,
|
|
322
|
+
description: t.description,
|
|
323
|
+
parameters: t.parameters,
|
|
324
|
+
output: { schema: { type: 'string' }, render: renderOutput },
|
|
325
|
+
async execute(args, exec) {
|
|
326
|
+
const a = args || {}
|
|
327
|
+
// Value-domain guard BEFORE building argv: project paths reach the
|
|
328
|
+
// engine's own shell/crontab/schtasks string interpolation and the
|
|
329
|
+
// filesystem; output writes a file. Model-controlled values with
|
|
330
|
+
// shell metacharacters (or output escaping the working area) are
|
|
331
|
+
// rejected here, never forwarded.
|
|
332
|
+
try {
|
|
333
|
+
assertSafePath(a.project, 'project')
|
|
334
|
+
assertSafeOutput(a.output)
|
|
335
|
+
// schedule clock params: the engine splices them into crontab /
|
|
336
|
+
// schtasks verbatim, so keep them inside the real clock range.
|
|
337
|
+
assertSafeClock(a.hour, 'hour', 0, 23)
|
|
338
|
+
assertSafeClock(a.minute, 'minute', 0, 59)
|
|
339
|
+
} catch (err) {
|
|
340
|
+
return `[skillopt ${t.name}] ${err.message}`
|
|
341
|
+
}
|
|
342
|
+
const argv = t.build(a)
|
|
343
|
+
// `command` must be the shell-quoted form for the platform executor;
|
|
344
|
+
// resolve() applies the executor's workdir/output-cap/sandbox defaults.
|
|
345
|
+
const request = {
|
|
346
|
+
command: quoteArgv(argv),
|
|
347
|
+
timeoutMs: config.timeoutMs,
|
|
348
|
+
signal: exec?.signal,
|
|
349
|
+
}
|
|
350
|
+
const spec = typeof shell.resolve === 'function' ? shell.resolve(request) : request
|
|
351
|
+
try {
|
|
352
|
+
const result = await runShell(shell, spec)
|
|
353
|
+
// Distinguish the executor's timeout (timedOut: true, exitCode null)
|
|
354
|
+
// from an abort/kill (exitCode null, no timedOut) so the marker is
|
|
355
|
+
// honest instead of lumping both under "signal".
|
|
356
|
+
const status = result?.timedOut
|
|
357
|
+
? 'timeout'
|
|
358
|
+
: (result?.exitCode ?? 'signal')
|
|
359
|
+
// rc.8 returns stdout/stderr as CollectedOutput { text, truncated, spillPath }
|
|
360
|
+
const fmt = (co) => {
|
|
361
|
+
if (co === undefined || co === null) return ''
|
|
362
|
+
if (typeof co === 'string') return co
|
|
363
|
+
const parts = []
|
|
364
|
+
if (co.text) parts.push(co.text)
|
|
365
|
+
if (co.truncated) {
|
|
366
|
+
parts.push(`[truncated${co.spillPath ? ` — full output at ${co.spillPath}` : ''}]`)
|
|
367
|
+
}
|
|
368
|
+
return parts.join('\n')
|
|
369
|
+
}
|
|
370
|
+
const stdout = fmt(result?.stdout)
|
|
371
|
+
const stderr = fmt(result?.stderr)
|
|
372
|
+
const tail = [stdout, stderr].filter(Boolean).join('\n').trim()
|
|
373
|
+
// Do NOT slice here: fmt() already carries the executor's truncation
|
|
374
|
+
// marker + spill path when output was capped. A second slice would
|
|
375
|
+
// hide data the executor already bounded and contradict the marker.
|
|
376
|
+
return [
|
|
377
|
+
`[skillopt ${t.name}] exit=${status}`,
|
|
378
|
+
tail ? tail : '(no output)',
|
|
379
|
+
].join('\n')
|
|
380
|
+
} catch (err) {
|
|
381
|
+
return `[skillopt ${t.name}] engine call failed: ${err?.message || String(err)}`
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
}),
|
|
385
|
+
))
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
ctx.logger?.info?.('[dsh-skillopt] registered 7 skillopt tools (status/dry-run/run/adopt/harvest/schedule/unschedule)')
|
|
389
|
+
return () => {
|
|
390
|
+
for (const dispose of disposers) {
|
|
391
|
+
try { dispose?.() } catch { /* already disposed */ }
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "suifei",
|
|
8
|
+
"homepage": "https://github.com/suifei/dsh-ai-team#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/suifei/dsh-ai-team.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/suifei/dsh-ai-team/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"deepseek-harness",
|
|
18
|
+
"dsh",
|
|
19
|
+
"dsh-plugin",
|
|
20
|
+
"ai-team",
|
|
21
|
+
"multi-agent",
|
|
22
|
+
"agent-team",
|
|
23
|
+
"task-ledger",
|
|
24
|
+
"wenyuan"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"icon": "./icon.svg",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./index.js",
|
|
32
|
+
"./client": "./client.js",
|
|
33
|
+
"./lib/*": "./lib/*",
|
|
34
|
+
"./icon": "./icon.svg"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"index.js",
|
|
38
|
+
"client.js",
|
|
39
|
+
"cordis.patch.yml",
|
|
40
|
+
"icon.svg",
|
|
41
|
+
"lib/**/*.js",
|
|
42
|
+
"lib/vendor/skillopt/scripts/**/*",
|
|
43
|
+
"lib/vendor/skillopt/skillopt_sleep/**/*",
|
|
44
|
+
"lib/vendor/skillopt/requirements.txt",
|
|
45
|
+
"lib/vendor/skillopt/LICENSE",
|
|
46
|
+
"skills/**/*",
|
|
47
|
+
"README.md",
|
|
48
|
+
"CHANGELOG.md",
|
|
49
|
+
"LICENSE"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"test": "node --test"
|
|
53
|
+
},
|
|
54
|
+
"dsh": {
|
|
55
|
+
"bundle": {
|
|
56
|
+
"patch": "./cordis.patch.yml"
|
|
57
|
+
},
|
|
58
|
+
"client": {
|
|
59
|
+
"platform": "web",
|
|
60
|
+
"immediately": true,
|
|
61
|
+
"inject": []
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: skillopt-sleep
|
|
3
|
+
description: "Use when the user wants the dsh agent to self-improve from past usage, asks about a nightly/offline 'sleep' or 'dream' cycle, skill/memory consolidation, or says things like 'make my agent better the more I use it', 'review my past sessions', 'learn my preferences', 'consolidate what you learned', 'run the sleep cycle', or wants to schedule background self-optimization. Drives the skillopt_sleep engine through the skillopt_* tools: harvest past sessions -> mine recurring tasks -> replay via a selected backend -> consolidate validated skills behind a held-out gate."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# SkillOpt-Sleep: usage-driven self-evolution for the dsh agent
|
|
7
|
+
|
|
8
|
+
SkillOpt-Sleep is Microsoft's [SkillOpt](https://github.com/microsoft/SkillOpt)
|
|
9
|
+
deployment-time companion engine: it reviews your past sessions (harvest), mines
|
|
10
|
+
recurring tasks (mine), replays them through a selected backend (replay), and
|
|
11
|
+
consolidates what it learns into skill documents behind a **held-out validation
|
|
12
|
+
gate** (consolidate).
|
|
13
|
+
|
|
14
|
+
This skill drives the engine through the 7 `skillopt_*` tools exposed by the
|
|
15
|
+
dsh-skillopt plugin. The default `mock` backend makes no model calls, which is
|
|
16
|
+
useful for verifying the plumbing; a real backend consumes your API budget.
|
|
17
|
+
|
|
18
|
+
## When to use
|
|
19
|
+
|
|
20
|
+
- "make my agent better the more I use it" / "learn my preferences across sessions"
|
|
21
|
+
- a one-off **offline self-evolution / sleep / dream** run (immediate or scheduled)
|
|
22
|
+
- review past sessions/trajectories and distill recurring tasks
|
|
23
|
+
- consolidate feedback into `AGENTS.md` / `SKILL.md` / managed skills
|
|
24
|
+
- schedule (cron) the cycle, or adopt a staged proposal
|
|
25
|
+
|
|
26
|
+
## The cycle (six stages)
|
|
27
|
+
|
|
28
|
+
1. **Harvest** — read-only scan of supported local session records → digests
|
|
29
|
+
2. **Mine** — digests → recurring task records (intent + outcome labels + checkable refs)
|
|
30
|
+
3. **Replay** — re-run tasks under the current skill+memory with the selected backend → (hard, soft) scores
|
|
31
|
+
4. **Consolidate** — reflect on failures → propose bounded edits → **validation gate** on a held-out slice (default: accept only on strict improvement)
|
|
32
|
+
5. **Stage** — write accepted proposals to `<project>/.skillopt-sleep/staging/<timestamp>/`. **Live files are unchanged.** A rejected run still has a report but no proposal files.
|
|
33
|
+
6. **Adopt** — explicit (or operator-configured `--auto-adopt`) copies staged files over live ones, backing up first.
|
|
34
|
+
|
|
35
|
+
## Driving it
|
|
36
|
+
|
|
37
|
+
Prefer the tools over hand-editing files:
|
|
38
|
+
|
|
39
|
+
| Tool | Behavior |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `skillopt_status` | state, engine availability, latest staged proposal & report |
|
|
42
|
+
| `skillopt_dry_run` | full preview (harvest+mine+replay), stages nothing |
|
|
43
|
+
| `skillopt_run` | full cycle, stages a proposal (live files unchanged by default) |
|
|
44
|
+
| `skillopt_adopt` | apply latest staged proposal (with backup) — the live-change boundary |
|
|
45
|
+
| `skillopt_harvest` | read-only show/export of mined tasks |
|
|
46
|
+
| `skillopt_schedule` / `skillopt_unschedule` | install/remove the nightly cron entry for this project |
|
|
47
|
+
|
|
48
|
+
Typical flow:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
# 1. check state (default mock backend, zero cost)
|
|
52
|
+
skillopt_status
|
|
53
|
+
|
|
54
|
+
# 2. preview the cycle
|
|
55
|
+
skillopt_dry_run project=<dir> source=<claude|codex|…>
|
|
56
|
+
|
|
57
|
+
# 3. real run (consumes the selected backend's API budget)
|
|
58
|
+
skillopt_run project=<dir> backend=<codex|claude|…> preferences="Prefer pytest; keep commits imperative."
|
|
59
|
+
|
|
60
|
+
# 4. review the report, then adopt
|
|
61
|
+
skillopt_adopt project=<dir>
|
|
62
|
+
|
|
63
|
+
# 5. schedule nightly at 03:17
|
|
64
|
+
skillopt_schedule project=<dir> hour=3 minute=17 backend=<codex>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Parameters
|
|
68
|
+
|
|
69
|
+
| Parameter | Default | Meaning |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `project` | config or cwd | project directory to evolve |
|
|
72
|
+
| `backend` | `mock` | `mock\|claude\|codex\|copilot\|cursor\|pi\|opencode\|handoff\|azure_openai` (mock = no model calls) |
|
|
73
|
+
| `source` | config | transcript source: `claude\|codex\|copilot\|cursor\|pi\|opencode\|auto` |
|
|
74
|
+
| `model` | backend default | replay model override |
|
|
75
|
+
| `maxTasks` | 40 | mined-task cap |
|
|
76
|
+
| `preferences` | empty | house rules for the reflection prior (e.g. "always use async/await") |
|
|
77
|
+
|
|
78
|
+
## Configuration (cordis.yml / bundle patch)
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
- insert:
|
|
82
|
+
- id: skillopt
|
|
83
|
+
name: './src/index.js'
|
|
84
|
+
config:
|
|
85
|
+
backend: codex
|
|
86
|
+
project: /path/to/project
|
|
87
|
+
preferences: 'Always use async/await'
|
|
88
|
+
# auto-adopt is OPERATOR-ONLY — the model cannot set it
|
|
89
|
+
autoAdopt: false
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Advanced engine keys go in `~/.skillopt-sleep/config.json`:
|
|
93
|
+
`gate_mode` (on/off), `gate_metric` (hard/soft/mixed), `gate_no_regression`,
|
|
94
|
+
`dream_rollouts`, `recall_k`, `evolve_memory` / `evolve_skill`.
|
|
95
|
+
|
|
96
|
+
## Hard rules
|
|
97
|
+
|
|
98
|
+
- **Never** hand-edit `AGENTS.md` / `SKILL.md` around `skillopt_adopt`; let the
|
|
99
|
+
engine's explicit adopt (or operator-configured `--auto-adopt`) apply the
|
|
100
|
+
staging manifest, backing up live files first.
|
|
101
|
+
- Harvest is read-only; `mock` replay has no side effects.
|
|
102
|
+
- Real backends send truncated transcript excerpts and derived tasks to the
|
|
103
|
+
selected provider for mining/replay/judging/reflection. For sensitive
|
|
104
|
+
sessions, export tasks first (`skillopt_harvest output=<file>`), redact, set
|
|
105
|
+
the top-level `"reviewed"` to `true`, then replay with `--tasks-file`; real
|
|
106
|
+
backends refuse unreviewed task files.
|
|
107
|
+
- Show the user the **held-out baseline → candidate** score and the exact
|
|
108
|
+
proposed edits before suggesting adoption. Evidence before adoption.
|
|
109
|
+
|
|
110
|
+
## Validate / demo (no API spend)
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pip install skillopt
|
|
114
|
+
python -m skillopt_sleep.experiments.run_experiment --persona researcher --assert-improves
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Deterministic synthetic demo: the score rises and the gate blocks a regression.
|
|
118
|
+
It validates the mechanism, not effectiveness on your own tasks.
|
|
119
|
+
|
|
120
|
+
See the [SkillOpt-Sleep docs](https://github.com/microsoft/SkillOpt/tree/main/docs/sleep)
|
|
121
|
+
for recorded results and limitations.
|