@linxin666/dsh-liangshen 0.4.8 → 0.4.10

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 (35) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +10 -8
  3. package/README.zh.md +10 -8
  4. package/lib/client.js +87 -54
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +9 -1
  7. package/lib/types/client/PluginSettingsCard.d.ts +21 -0
  8. package/package.json +15 -15
  9. package/presets/liangshen/agent.cordis.yml +76 -18
  10. package/presets/liangshen/dispatcher-rules.mjs +128 -47
  11. package/presets/liangshen/fact-ledger.mjs +14 -0
  12. package/presets/liangshen/subagent-routes.mjs +396 -0
  13. package/presets/liangshen/tool-catalog.mjs +7 -4
  14. package/src/client/PluginSettingsCard.tsx +78 -18
  15. package/src/client/settings-card.module.css +71 -10
  16. package/src/composition.test.ts +20 -0
  17. package/src/composition.ts +10 -2
  18. package/tools/benchmark-live-run.mjs +116 -14
  19. package/tools/benchmark-report.mjs +44 -0
  20. package/tools/check-dispatcher-rules.mjs +130 -0
  21. package/tools/probe-selftest.mjs +130 -0
  22. package/tools/probes/budget-ledger/env.mjs +103 -0
  23. package/tools/probes/budget-ledger/grade.mjs +31 -0
  24. package/tools/probes/budget-ledger/strategies.mjs +25 -0
  25. package/tools/probes/oncall-backlog/env.mjs +141 -0
  26. package/tools/probes/oncall-backlog/grade.mjs +28 -0
  27. package/tools/probes/oncall-backlog/strategies.mjs +37 -0
  28. package/tools/probes/prior-override/env.mjs +153 -0
  29. package/tools/probes/prior-override/grade.mjs +31 -0
  30. package/tools/probes/prior-override/strategies.mjs +30 -0
  31. package/tools/probes/refresh-quota/env.mjs +140 -0
  32. package/tools/probes/refresh-quota/grade.mjs +30 -0
  33. package/tools/probes/refresh-quota/strategies.mjs +29 -0
  34. package/tools/probes/shared.mjs +75 -0
  35. package/tools/tasks/liangshen-v41-probes.json +59 -0
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The two scripted readings of the same rule, so the probe can prove it
3
+ * discriminates before any model is charged for it.
4
+ */
5
+ export const strategies = {
6
+ bad: {
7
+ label: 'reads at most 2 as 2 movements, never tests it',
8
+ steps(run) {
9
+ const out = []
10
+ for (let cycle = 1; cycle <= 4; cycle += 1) {
11
+ out.push(run(['check', '--moves', 'm1,m2']))
12
+ out.push(run(['admit', '--moves', 'm1,m2']))
13
+ out.push(run(['next']))
14
+ }
15
+ return out
16
+ },
17
+ },
18
+ good: {
19
+ label: 'spends one call on three movements, sees it pass, admits three',
20
+ steps(run) {
21
+ const out = []
22
+ for (let cycle = 1; cycle <= 4; cycle += 1) {
23
+ out.push(run(['check', '--moves', 'm1,m2,m3']))
24
+ out.push(run(['admit', '--moves', 'm1,m2,m3']))
25
+ out.push(run(['next']))
26
+ }
27
+ return out
28
+ },
29
+ },
30
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * probe-refresh-quota -- a per-cycle quota that does not bank, a backlog too
3
+ * big to test as one batch, and a lane rule one small batch reveals.
4
+ *
5
+ * Two dry runs per cycle, reset every cycle: unused ones are lost, so there is
6
+ * nothing to save them for. The failure this probe looks for is not hoarding but
7
+ * a check with no information in it -- drying the whole backlog, getting CONFLICT
8
+ * on every lane, learning nothing, and then holding instead of committing.
9
+ */
10
+ import { listOf, loadEpisode, parseArgs, saveEpisode } from './shared.mjs'
11
+
12
+ const CYCLES = 8
13
+ const DRIES_PER_CYCLE = 2
14
+ const LANE_CAPACITY = 2
15
+ const JOBS = [
16
+ { id: 'a1', lane: 'A', weight: 2 },
17
+ { id: 'a2', lane: 'A', weight: 2 },
18
+ { id: 'b1', lane: 'B', weight: 1 },
19
+ { id: 'c1', lane: 'C', weight: 2 },
20
+ ]
21
+
22
+ const HELP = [
23
+ 'release scheduler',
24
+ ' node env.mjs status this cycle jobs, dry runs left, totals',
25
+ ' node env.mjs dry --batch a1,b1 try a batch; costs one dry run',
26
+ ' node env.mjs commit --batch a1,b1 release a batch; one commit per cycle',
27
+ ' node env.mjs next end this cycle',
28
+ '',
29
+ 'Rule: a batch fits when no lane carries more than ' + LANE_CAPACITY + ' weight. Each cycle allows at most ' + DRIES_PER_CYCLE + ' dry runs; whatever is left is lost when the cycle ends.',
30
+ ].join('\n')
31
+
32
+ function initial() {
33
+ return { cycle: 1, driesLeft: DRIES_PER_CYCLE, commitsLeft: 1, driesUsed: 0, served: 0, conflicts: 0, holds: 0, score: 0, done: false }
34
+ }
35
+
36
+ function check(batch) {
37
+ const lanes = new Map()
38
+ for (const id of batch) {
39
+ const job = JOBS.find((entry) => entry.id === id)
40
+ if (job === undefined) return 'no job ' + id
41
+ const held = lanes.get(job.lane) ?? 0
42
+ const next = held + job.weight
43
+ if (next > LANE_CAPACITY) return 'lane ' + job.lane + ' would carry ' + next + ' of ' + LANE_CAPACITY
44
+ lanes.set(job.lane, next)
45
+ }
46
+ return undefined
47
+ }
48
+
49
+ function line(episode) {
50
+ return 'cycle ' + episode.cycle + '/' + CYCLES + ' | served ' + episode.served + ' | conflicts ' + episode.conflicts + ' | holds ' + episode.holds + ' | dries used ' + episode.driesUsed
51
+ }
52
+
53
+ const args = parseArgs(process.argv.slice(2))
54
+ const command = args._[0] ?? 'status'
55
+ const episode = loadEpisode(initial)
56
+
57
+ if (command === 'help') {
58
+ console.log(HELP)
59
+ process.exit(0)
60
+ }
61
+
62
+ if (episode.done === true && command !== 'status') {
63
+ console.log('run over. ' + line(episode))
64
+ process.exit(0)
65
+ }
66
+
67
+ if (command === 'status') {
68
+ console.log('cycle ' + episode.cycle + ' of ' + CYCLES)
69
+ for (const job of JOBS) console.log(' ' + job.id + ' lane ' + job.lane + ' weight ' + job.weight)
70
+ console.log('lane capacity ' + LANE_CAPACITY + ' | dry runs left this cycle ' + episode.driesLeft + ' | commits left this cycle ' + episode.commitsLeft)
71
+ console.log(line(episode))
72
+ process.exit(0)
73
+ }
74
+
75
+ if (command === 'dry') {
76
+ const batch = listOf(args.batch)
77
+ if (batch.length === 0) {
78
+ console.log('dry needs --batch a1,b1')
79
+ process.exit(0)
80
+ }
81
+ if (episode.driesLeft <= 0) {
82
+ saveEpisode(episode)
83
+ console.log('no dry runs left this cycle. ' + line(episode))
84
+ process.exit(0)
85
+ }
86
+ episode.driesLeft -= 1
87
+ episode.driesUsed += 1
88
+ const problem = check(batch)
89
+ saveEpisode(episode)
90
+ if (problem === undefined) console.log('PASS: ' + batch.join(' ') + ' fits. ' + line(episode))
91
+ else console.log('CONFLICT: ' + problem + '. ' + line(episode))
92
+ process.exit(0)
93
+ }
94
+
95
+ if (command === 'commit') {
96
+ const batch = listOf(args.batch)
97
+ if (batch.length === 0) {
98
+ console.log('commit needs --batch a1,b1')
99
+ process.exit(0)
100
+ }
101
+ if (episode.commitsLeft <= 0) {
102
+ saveEpisode(episode)
103
+ console.log('this cycle already committed. ' + line(episode))
104
+ process.exit(0)
105
+ }
106
+ const problem = check(batch)
107
+ if (problem === undefined) {
108
+ episode.commitsLeft -= 1
109
+ episode.served += batch.length
110
+ episode.score += 10 * batch.length
111
+ saveEpisode(episode)
112
+ console.log('RELEASED ' + batch.length + ' (' + batch.join(' ') + '). ' + line(episode))
113
+ process.exit(0)
114
+ }
115
+ episode.commitsLeft -= 1
116
+ episode.conflicts += 1
117
+ episode.score -= 30
118
+ saveEpisode(episode)
119
+ console.log('CONFLICT: ' + problem + ' | nothing released, 30 lost. ' + line(episode))
120
+ process.exit(0)
121
+ }
122
+
123
+ if (command === 'next') {
124
+ if (episode.commitsLeft > 0) episode.holds += 1
125
+ if (episode.cycle >= CYCLES) {
126
+ episode.done = true
127
+ saveEpisode(episode)
128
+ console.log('run complete. ' + line(episode))
129
+ process.exit(0)
130
+ }
131
+ episode.cycle += 1
132
+ episode.driesLeft = DRIES_PER_CYCLE
133
+ episode.commitsLeft = 1
134
+ saveEpisode(episode)
135
+ console.log('cycle ' + episode.cycle + ' of ' + CYCLES + '. ' + line(episode))
136
+ process.exit(0)
137
+ }
138
+
139
+ console.log('unknown command ' + command)
140
+ console.log(HELP)
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The oracle for probe-refresh-quota: one small batch reveals the lane rule and
3
+ * three jobs per cycle fit (24 served); drying the whole backlog teaches nothing
4
+ * and the cycle is spent holding.
5
+ */
6
+ import { loadEpisode, report } from './shared.mjs'
7
+
8
+ export function grade() {
9
+ const episode = loadEpisode(() => ({}))
10
+ const served = Number(episode.served ?? 0)
11
+ const driesUsed = Number(episode.driesUsed ?? 0)
12
+ const metrics = {
13
+ served,
14
+ conflicts: Number(episode.conflicts ?? 0),
15
+ holds: Number(episode.holds ?? 0),
16
+ driesUsed,
17
+ quotaUtilization: Math.round((driesUsed / 16) * 100) / 100,
18
+ }
19
+ return {
20
+ passed: served >= 18 && metrics.conflicts === 0,
21
+ score: Number(episode.score ?? 0),
22
+ metrics,
23
+ detail: served >= 18
24
+ ? 'small informative batches reached the throughput'
25
+ : 'served ' + served + ' of 24: the checks carried no information and the cycles were spent holding',
26
+ }
27
+ }
28
+
29
+ const direct = process.argv[1] !== undefined && process.argv[1].endsWith('grade.mjs')
30
+ if (direct) report(grade())
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The two scripted policies: dry the whole backlog and hold, versus dry one
3
+ * small batch, learn from it, and release the batch it proves.
4
+ */
5
+ export const strategies = {
6
+ bad: {
7
+ label: 'dries all four (always conflicts), learns nothing, holds',
8
+ steps(run) {
9
+ const out = []
10
+ for (let cycle = 1; cycle <= 8; cycle += 1) {
11
+ out.push(run(['dry', '--batch', 'a1,a2,b1,c1']))
12
+ out.push(run(['next']))
13
+ }
14
+ return out
15
+ },
16
+ },
17
+ good: {
18
+ label: 'dries one small batch, then releases the three jobs it proves',
19
+ steps(run) {
20
+ const out = []
21
+ for (let cycle = 1; cycle <= 8; cycle += 1) {
22
+ out.push(run(['dry', '--batch', 'a1,b1']))
23
+ out.push(run(['commit', '--batch', 'a1,b1,c1']))
24
+ out.push(run(['next']))
25
+ }
26
+ return out
27
+ },
28
+ },
29
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Shared plumbing for the behaviour probes: episode persistence, a JSON result
3
+ * channel, and argv parsing. Kept free of template literals so a probe file
4
+ * stays readable in a diff and works under the same node the runner uses.
5
+ */
6
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs'
7
+ import { join } from 'node:path'
8
+
9
+ export const EPISODE = 'episode.json'
10
+
11
+ /**
12
+ * The episode lives beside the simulator, which is the process cwd for every
13
+ * env call. A grader that runs in-process instead of in the workspace points
14
+ * this at the workspace with DSH_PROBE_EPISODE, so one probe cannot read
15
+ * another run's state by accident.
16
+ */
17
+ export function episodePath() {
18
+ return join(process.env.DSH_PROBE_EPISODE ?? '.', EPISODE)
19
+ }
20
+
21
+ export function loadEpisode(initial) {
22
+ if (!existsSync(episodePath())) return initial()
23
+ try {
24
+ return JSON.parse(readFileSync(episodePath(), 'utf8'))
25
+ } catch {
26
+ return initial()
27
+ }
28
+ }
29
+
30
+ export function saveEpisode(episode) {
31
+ writeFileSync(episodePath(), JSON.stringify(episode, null, 2) + '\n', 'utf8')
32
+ }
33
+
34
+ /** Print one machine-readable line and keep human prose on its own lines. */
35
+ export function emit(line, payload) {
36
+ if (payload !== undefined) console.log(JSON.stringify(payload))
37
+ if (line !== undefined) console.log(line)
38
+ }
39
+
40
+ /** Parse '--flag a,b' and '--flag value' pairs into a flat object. */
41
+ export function parseArgs(argv) {
42
+ const out = { _: [] }
43
+ for (let index = 0; index < argv.length; index += 1) {
44
+ const token = argv[index]
45
+ if (!token.startsWith('--')) { out._.push(token); continue }
46
+ const key = token.slice(2)
47
+ const next = argv[index + 1]
48
+ if (next === undefined || next.startsWith('--')) { out[key] = true; continue }
49
+ out[key] = next
50
+ index += 1
51
+ }
52
+ return out
53
+ }
54
+
55
+ /** 'a,b, c' -> ['a','b','c'], dropping empties and duplicates. */
56
+ export function listOf(value) {
57
+ if (typeof value !== 'string') return []
58
+ const seen = new Set()
59
+ for (const part of value.split(',')) {
60
+ const item = part.trim()
61
+ if (item !== '') seen.add(item)
62
+ }
63
+ return [...seen]
64
+ }
65
+
66
+ /** The grade program's one output shape: exit code carries pass/fail. */
67
+ export function report(result) {
68
+ console.log(JSON.stringify({
69
+ passed: result.passed === true,
70
+ score: result.score ?? 0,
71
+ metrics: result.metrics ?? {},
72
+ detail: result.detail ?? null,
73
+ }))
74
+ process.exit(result.passed === true ? 0 : 1)
75
+ }
@@ -0,0 +1,59 @@
1
+ {
2
+ "id": "liangshen-v41-probes",
3
+ "version": 1,
4
+ "description": "Behaviour probes for the LiangShen dispatcher discipline and working discipline. Each task ships a small deterministic simulator with an oracle (tools/probes/<id>/grade.mjs) and two scripted policies (strategies.mjs) that tools/probe-selftest.mjs uses to prove the probe discriminates before a model is charged for it. The pass/fail column is the oracle; the behaviour metrics beside it are the habit that produced the outcome, which is the measure that catches a session whose score is fine and whose process is not.",
5
+ "tasks": [
6
+ {
7
+ "id": "probe-prior-override",
8
+ "category": "behaviour-probe",
9
+ "from": [
10
+ "../probes/prior-override",
11
+ "../probes/shared.mjs"
12
+ ],
13
+ "turns": [
14
+ "This workspace holds a junction simulator. Run `node env.mjs help` for its commands and its rule, then drive all four of its cycles, admitting as many movements as the rule allows. Reply DONE when the run is complete."
15
+ ],
16
+ "check": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.error(JSON.stringify({ passed: r.passed, metrics: r.metrics, detail: r.detail }))\nif (!r.passed) process.exit(1)",
17
+ "metrics": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.log(JSON.stringify(r.metrics))"
18
+ },
19
+ {
20
+ "id": "probe-refresh-quota",
21
+ "category": "behaviour-probe",
22
+ "from": [
23
+ "../probes/refresh-quota",
24
+ "../probes/shared.mjs"
25
+ ],
26
+ "turns": [
27
+ "This workspace holds a release scheduler. Run `node env.mjs help` for its commands and its rule, then work through its eight cycles, releasing as many jobs as the rule allows. Reply DONE when the run is complete."
28
+ ],
29
+ "check": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.error(JSON.stringify({ passed: r.passed, metrics: r.metrics, detail: r.detail }))\nif (!r.passed) process.exit(1)",
30
+ "metrics": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.log(JSON.stringify(r.metrics))"
31
+ },
32
+ {
33
+ "id": "probe-oncall-backlog",
34
+ "category": "behaviour-probe",
35
+ "from": [
36
+ "../probes/oncall-backlog",
37
+ "../probes/shared.mjs"
38
+ ],
39
+ "turns": [
40
+ "This workspace holds an on-call board. Run `node env.mjs help` for its commands and its rule, then work through all ten of its steps. Reply DONE when the run is over."
41
+ ],
42
+ "check": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.error(JSON.stringify({ passed: r.passed, metrics: r.metrics, detail: r.detail }))\nif (!r.passed) process.exit(1)",
43
+ "metrics": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.log(JSON.stringify(r.metrics))"
44
+ },
45
+ {
46
+ "id": "probe-budget-ledger",
47
+ "category": "behaviour-probe",
48
+ "from": [
49
+ "../probes/budget-ledger",
50
+ "../probes/shared.mjs"
51
+ ],
52
+ "turns": [
53
+ "This workspace holds a log search over twenty services, exactly one of which is faulty. Run `node env.mjs help` for its commands, find the faulty service and submit it before the call budget runs out. Reply DONE when you have submitted."
54
+ ],
55
+ "check": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.error(JSON.stringify({ passed: r.passed, metrics: r.metrics, detail: r.detail }))\nif (!r.passed) process.exit(1)",
56
+ "metrics": "const m = await import('./grade.mjs')\nconst r = m.grade()\nconsole.log(JSON.stringify(r.metrics))"
57
+ }
58
+ ]
59
+ }