@shuind/dsh-codex-harness 0.2.21 → 0.3.0
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 +185 -0
- package/README.md +38 -50
- package/RELEASE.md +61 -0
- package/assets/codex.svg +5 -0
- package/cordis.patch.yml +181 -6
- package/docs/preset-library.md +33 -23
- package/docs/tool-policy-benchmark.json +310 -0
- package/docs/tool-policy.md +148 -0
- package/lib/client.js +4774 -2416
- package/lib/compact-command.js +416 -0
- package/lib/compaction.js +141 -12
- package/lib/hybrid-executor.js +1196 -0
- package/lib/index.js +3658 -2334
- package/lib/preferences.js +117 -0
- package/lib/tool-policy.js +2422 -0
- package/lib/typert.js +86 -79
- package/lib/types/client/activity.d.ts +33 -9
- package/lib/types/client/activity.js +4 -3
- package/lib/types/client/desktop.d.ts +67 -0
- package/lib/types/client/desktop.js +229 -0
- package/lib/types/client/index.d.ts +207 -110
- package/lib/types/client/index.js +99 -492
- package/lib/types/client/policy-drafts.d.ts +25 -0
- package/lib/types/client/policy-drafts.js +47 -0
- package/lib/types/client/policy-locale.d.ts +260 -0
- package/lib/types/client/policy-locale.js +357 -0
- package/lib/types/client/preset-manager.d.ts +38 -10
- package/lib/types/client/preset-manager.js +235 -185
- package/lib/types/client/preset-requests.d.ts +12 -0
- package/lib/types/client/preset-requests.js +101 -0
- package/lib/types/client/tool-policy.d.ts +33 -0
- package/lib/types/client/tool-policy.js +336 -0
- package/lib/types/contracts/preset-editor-schema.d.ts +78 -0
- package/lib/types/contracts/preset-editor-schema.js +95 -0
- package/lib/types/{prompt.js → contracts/prompt.js} +13 -7
- package/lib/types/{settings.d.ts → contracts/settings.d.ts} +11 -4
- package/lib/types/{settings.js → contracts/settings.js} +22 -6
- package/lib/types/contracts/tool-policy-contract.d.ts +63 -0
- package/lib/types/contracts/tool-policy-contract.js +33 -0
- package/lib/types/contracts/ui-contracts.d.ts +92 -0
- package/lib/types/contracts/ui-contracts.js +83 -0
- package/lib/types/entries/client.d.ts +10 -0
- package/lib/types/entries/client.js +10 -0
- package/lib/types/{compact-command.d.ts → entries/compact-command.d.ts} +2 -0
- package/lib/types/entries/compact-command.js +176 -0
- package/lib/types/{compaction.d.ts → entries/compaction.d.ts} +15 -3
- package/lib/types/{compaction.js → entries/compaction.js} +47 -11
- package/lib/types/entries/hybrid-executor.d.ts +19 -0
- package/lib/types/entries/hybrid-executor.js +57 -0
- package/lib/types/entries/index.d.ts +66 -0
- package/lib/types/entries/index.js +192 -0
- package/lib/types/entries/preferences.d.ts +11 -0
- package/lib/types/entries/preferences.js +16 -0
- package/lib/types/entries/tool-policy.d.ts +97 -0
- package/lib/types/entries/tool-policy.js +158 -0
- package/lib/types/entries/typert.host.d.ts +23 -0
- package/lib/types/entries/typert.host.js +24 -0
- package/lib/types/hybrid/codex-hybrid-executor.d.ts +44 -0
- package/lib/types/hybrid/codex-hybrid-executor.js +257 -0
- package/lib/types/hybrid/hybrid-sdk.d.ts +13 -0
- package/lib/types/hybrid/hybrid-sdk.js +196 -0
- package/lib/types/hybrid/program-calls.d.ts +28 -0
- package/lib/types/hybrid/program-calls.js +193 -0
- package/lib/types/hybrid/subcall-scheduler.d.ts +90 -0
- package/lib/types/hybrid/subcall-scheduler.js +343 -0
- package/lib/types/policy/deferred-tools.d.ts +42 -0
- package/lib/types/policy/deferred-tools.js +264 -0
- package/lib/types/policy/overlay-installer.d.ts +12 -0
- package/lib/types/policy/overlay-installer.js +179 -0
- package/lib/types/policy/rule-resolver.d.ts +94 -0
- package/lib/types/policy/rule-resolver.js +114 -0
- package/lib/types/policy/tool-capabilities.d.ts +33 -0
- package/lib/types/policy/tool-capabilities.js +46 -0
- package/lib/types/{activity.d.ts → presets/activity.d.ts} +3 -5
- package/lib/types/{activity.js → presets/activity.js} +51 -27
- package/lib/types/presets/desktop-preset.d.ts +22 -0
- package/lib/types/presets/desktop-preset.js +43 -0
- package/lib/types/presets/preset-editor.d.ts +47 -0
- package/lib/types/presets/preset-editor.js +81 -0
- package/lib/types/presets/preset-prompt-catalog.d.ts +23 -0
- package/lib/types/presets/preset-prompt-catalog.js +215 -0
- package/lib/types/presets/preset-tool-catalog.d.ts +5 -0
- package/lib/types/presets/preset-tool-catalog.js +58 -0
- package/lib/types/presets/runtime-enhancements.d.ts +45 -0
- package/lib/types/presets/runtime-enhancements.js +349 -0
- package/lib/types/presets/small-window-compaction.d.ts +15 -0
- package/lib/types/presets/small-window-compaction.js +121 -0
- package/lib/types/responses/compact-checkpoint.d.ts +27 -0
- package/lib/types/responses/compact-checkpoint.js +257 -0
- package/lib/types/responses/fetch-transport.d.ts +16 -0
- package/lib/types/responses/fetch-transport.js +257 -0
- package/lib/types/responses/remote-compact.d.ts +13 -0
- package/lib/types/responses/remote-compact.js +319 -0
- package/lib/types/responses/sse-diagnostics.d.ts +9 -0
- package/lib/types/responses/sse-diagnostics.js +157 -0
- package/lib/types/responses/wire-rewrite.d.ts +35 -0
- package/lib/types/responses/wire-rewrite.js +237 -0
- package/lib/types/tools/exec-output.d.ts +58 -0
- package/lib/types/tools/exec-output.js +173 -0
- package/lib/types/tools/exec-plan-tools.d.ts +37 -0
- package/lib/types/tools/exec-plan-tools.js +265 -0
- package/lib/types/tools/exec-runner.d.ts +21 -0
- package/lib/types/tools/exec-runner.js +385 -0
- package/lib/types/tools/patch-tool.d.ts +16 -0
- package/lib/types/tools/patch-tool.js +258 -0
- package/lib/types/{patch.d.ts → tools/patch.d.ts} +1 -1
- package/lib/types/{patch.js → tools/patch.js} +96 -21
- package/locale/en.json +6 -0
- package/locale/hybrid-executor/en.json +6 -0
- package/locale/hybrid-executor/zh.json +6 -0
- package/locale/tool-policy/en.json +6 -0
- package/locale/tool-policy/zh.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +297 -299
- package/presets/{codex-collaboration → codex-hybrid}/agent.cordis.yml +45 -48
- package/presets/codex-hybrid/preset.yml +3 -0
- package/scripts/benchmark-tool-policy.mjs +186 -0
- package/scripts/build-preset.mjs +19 -0
- package/scripts/clean-build.mjs +11 -0
- package/src/client/activity.ts +83 -0
- package/src/client/desktop.tsx +276 -0
- package/src/client/index.tsx +391 -0
- package/src/client/policy-drafts.ts +56 -0
- package/src/client/policy-locale.ts +362 -0
- package/src/client/preset-manager.tsx +376 -0
- package/src/client/preset-requests.ts +113 -0
- package/src/client/tool-policy.tsx +402 -0
- package/src/contracts/preset-editor-schema.ts +110 -0
- package/src/contracts/prompt.ts +66 -0
- package/src/contracts/settings.ts +103 -0
- package/src/contracts/tool-policy-contract.ts +93 -0
- package/src/contracts/ui-contracts.ts +173 -0
- package/src/entries/client.tsx +14 -0
- package/src/entries/compact-command.ts +256 -0
- package/src/entries/compaction.ts +218 -0
- package/src/entries/hybrid-executor.ts +76 -0
- package/src/entries/index.ts +298 -0
- package/src/entries/preferences.ts +17 -0
- package/src/entries/tool-policy.ts +162 -0
- package/src/entries/typert.host.ts +29 -0
- package/src/hybrid/codex-hybrid-executor.ts +310 -0
- package/src/hybrid/hybrid-sdk.ts +217 -0
- package/src/hybrid/program-calls.ts +202 -0
- package/src/hybrid/subcall-scheduler.ts +446 -0
- package/src/policy/deferred-tools.ts +331 -0
- package/src/policy/overlay-installer.ts +191 -0
- package/src/policy/rule-resolver.ts +128 -0
- package/src/policy/tool-capabilities.ts +88 -0
- package/src/presets/activity.ts +146 -0
- package/src/presets/desktop-preset.ts +60 -0
- package/src/presets/preset-editor.ts +101 -0
- package/src/presets/preset-prompt-catalog.ts +221 -0
- package/src/presets/preset-tool-catalog.ts +58 -0
- package/src/presets/runtime-enhancements.ts +415 -0
- package/src/presets/small-window-compaction.ts +166 -0
- package/src/responses/compact-checkpoint.ts +264 -0
- package/src/responses/fetch-transport.ts +290 -0
- package/src/responses/remote-compact.ts +393 -0
- package/src/responses/sse-diagnostics.ts +156 -0
- package/src/responses/wire-rewrite.ts +261 -0
- package/src/tools/exec-output.ts +211 -0
- package/src/tools/exec-plan-tools.ts +307 -0
- package/src/tools/exec-runner.ts +445 -0
- package/src/tools/patch-tool.ts +331 -0
- package/src/tools/patch.ts +328 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +110 -0
- package/lib/installer.js +0 -237
- package/lib/invariant.js +0 -23
- package/lib/types/activity-types.d.ts +0 -6
- package/lib/types/activity-types.js +0 -3
- package/lib/types/client/preset-copy.d.ts +0 -42
- package/lib/types/client/preset-copy.js +0 -81
- package/lib/types/compact-command.js +0 -79
- package/lib/types/context.d.ts +0 -8
- package/lib/types/context.js +0 -14
- package/lib/types/exec.d.ts +0 -46
- package/lib/types/exec.js +0 -365
- package/lib/types/index.d.ts +0 -95
- package/lib/types/index.js +0 -738
- package/lib/types/installer.d.ts +0 -27
- package/lib/types/installer.js +0 -146
- package/lib/types/invariant.d.ts +0 -16
- package/lib/types/invariant.js +0 -22
- package/lib/types/preset-contract.d.ts +0 -69
- package/lib/types/preset-contract.js +0 -22
- package/lib/types/preset-editor-remote.d.ts +0 -30
- package/lib/types/preset-editor-remote.js +0 -37
- package/lib/types/preset-editor.d.ts +0 -69
- package/lib/types/preset-editor.js +0 -557
- package/lib/types/preset-templates.d.ts +0 -36
- package/lib/types/preset-templates.js +0 -12
- package/lib/types/prompt-sections.d.ts +0 -15
- package/lib/types/prompt-sections.js +0 -23
- package/lib/types/remote.d.ts +0 -40
- package/lib/types/remote.js +0 -683
- package/lib/types/typert.host.d.ts +0 -47
- package/lib/types/typert.host.js +0 -99
- package/presets/codex-collaboration/preset.yml +0 -3
- /package/lib/types/{prompt.d.ts → contracts/prompt.d.ts} +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
1
|
+
# Experimental asymmetric Codex hybrid preset: native apply_patch/exec_command/update_plan
|
|
2
|
+
# paired with run_code SDK batching for read/glob/grep/web_fetch and deferred secondary tools.
|
|
3
3
|
|
|
4
4
|
- id: persona
|
|
5
5
|
name: '@deepseek-ai/dsh-persona'
|
|
6
6
|
config:
|
|
7
|
-
# Keep identity, model, cwd, and runtime context in one persona section.
|
|
8
7
|
prefix: >-
|
|
9
|
-
You are Codex, a coding agent based on the {{model}} model.
|
|
8
|
+
You are Codex, a coding agent based on the {{model}} model.
|
|
10
9
|
includeRuntimeContext: true
|
|
11
10
|
|
|
12
11
|
- id: agent-instructions
|
|
@@ -14,38 +13,50 @@
|
|
|
14
13
|
config:
|
|
15
14
|
maxBytes: 65536
|
|
16
15
|
|
|
17
|
-
# The editable Codex operating prompt and its four core tools are available
|
|
18
|
-
# only inside this preset. Global request enhancements are mounted by the
|
|
19
|
-
# bundle row and must not be installed twice in this agent scope.
|
|
20
16
|
- id: codex-tools
|
|
21
17
|
name: '@shuind/dsh-codex-harness'
|
|
22
18
|
config:
|
|
23
19
|
globalEnhancements: false
|
|
24
20
|
codexCore: true
|
|
25
21
|
|
|
26
|
-
# Background-job guidance and completion delivery belong to the official
|
|
27
|
-
# dsh-tool-jobs plugin. Use wakeup delivery so an idle agent also learns about
|
|
28
|
-
# a completed job without needing a separate user/tool wake.
|
|
29
22
|
- id: codex-jobs
|
|
30
23
|
name: '@deepseek-ai/dsh-tool-jobs'
|
|
31
24
|
config:
|
|
32
25
|
completionDelivery: wakeup
|
|
33
26
|
|
|
34
|
-
# The generic DSH pi-ai adapter still owns the user's configured provider,
|
|
35
|
-
# endpoint, API key, and model. The global Codex capability layer owns the
|
|
36
|
-
# optional remote-first transport wrapper and falls back to the generic path.
|
|
37
|
-
|
|
38
|
-
# Keep the local tool mounted as the fallback. Codex rewrites the final GPT
|
|
39
|
-
# Responses request to a hosted web_search tool first; a failed remote request
|
|
40
|
-
# is retried through this unchanged local function-tool path.
|
|
41
27
|
- id: codex-web-search
|
|
42
28
|
name: '@deepseek-ai/dsh-tool-web'
|
|
43
29
|
config:
|
|
44
30
|
search: true
|
|
45
|
-
fetch:
|
|
31
|
+
fetch: true
|
|
32
|
+
|
|
33
|
+
- id: tool-fs
|
|
34
|
+
name: '@deepseek-ai/dsh-tool-fs'
|
|
35
|
+
config:
|
|
36
|
+
read: true
|
|
37
|
+
readImage: true
|
|
38
|
+
write: false
|
|
39
|
+
edit: false
|
|
40
|
+
applyPatch: false
|
|
41
|
+
|
|
42
|
+
- id: tool-fs-search
|
|
43
|
+
name: '@deepseek-ai/dsh-tool-fs-search'
|
|
44
|
+
config:
|
|
45
|
+
sampleOverCapGlobResults: false
|
|
46
|
+
|
|
47
|
+
- id: hybrid-executor
|
|
48
|
+
name: '@shuind/dsh-codex-harness/hybrid-executor'
|
|
49
|
+
config:
|
|
50
|
+
hiddenTools:
|
|
51
|
+
- todo_write
|
|
52
|
+
deferredTools:
|
|
53
|
+
- create_goal
|
|
54
|
+
- get_goal
|
|
55
|
+
- ralph
|
|
56
|
+
- subagent_fork
|
|
57
|
+
- update_goal
|
|
58
|
+
- workflow
|
|
46
59
|
|
|
47
|
-
# PTY execution is optional. Pipe-backed exec_command remains available on all
|
|
48
|
-
# platforms through the shell capability consumed by the Codex tool layer.
|
|
49
60
|
- id: codex-terminal
|
|
50
61
|
name: cordis:group
|
|
51
62
|
group: true
|
|
@@ -61,9 +72,13 @@
|
|
|
61
72
|
config:
|
|
62
73
|
timeoutMs: 300000
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
- id: terminal-pwsh
|
|
76
|
+
name: '@deepseek-ai/dsh-terminal-bash'
|
|
77
|
+
disabled: !!js process.platform !== 'win32'
|
|
78
|
+
config:
|
|
79
|
+
shellDialect: pwsh
|
|
80
|
+
timeoutMs: 300000
|
|
81
|
+
|
|
67
82
|
- id: compaction
|
|
68
83
|
name: cordis:group
|
|
69
84
|
group: true
|
|
@@ -74,7 +89,7 @@
|
|
|
74
89
|
- id: compaction-basic
|
|
75
90
|
name: '@shuind/dsh-codex-harness/compaction'
|
|
76
91
|
config:
|
|
77
|
-
thresholdRatio: 0.
|
|
92
|
+
thresholdRatio: 0.9
|
|
78
93
|
|
|
79
94
|
- id: command-compact
|
|
80
95
|
name: '@shuind/dsh-codex-harness/compact-command'
|
|
@@ -82,25 +97,19 @@
|
|
|
82
97
|
- id: tool-result-pruner
|
|
83
98
|
name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
|
|
84
99
|
config:
|
|
85
|
-
thresholdChars:
|
|
86
|
-
headChars:
|
|
87
|
-
tailChars:
|
|
100
|
+
thresholdChars: 40960
|
|
101
|
+
headChars: 20000
|
|
102
|
+
tailChars: 20000
|
|
88
103
|
|
|
89
|
-
# Skills are the dsh extensibility seam and do not change the four Codex core
|
|
90
|
-
# tool names.
|
|
91
104
|
- id: skill-filesystem
|
|
92
105
|
name: '@deepseek-ai/dsh-skill-filesystem'
|
|
93
106
|
|
|
94
107
|
- id: tool-skill
|
|
95
108
|
name: '@deepseek-ai/dsh-tool-skill'
|
|
96
109
|
|
|
97
|
-
# Goal state remains host-owned and session-keyed. This row adds the official
|
|
98
|
-
# model-facing goal lifecycle without moving the goal service into the preset.
|
|
99
110
|
- id: tool-goal
|
|
100
111
|
name: '@deepseek-ai/dsh-tool-goal'
|
|
101
112
|
|
|
102
|
-
# Official plan mode supplies the reviewed exit_plan_mode flow. Keep the
|
|
103
|
-
# Codex update_plan and todo_write tools out of this planning phase.
|
|
104
113
|
- id: planning
|
|
105
114
|
name: cordis:group
|
|
106
115
|
group: true
|
|
@@ -123,8 +132,6 @@
|
|
|
123
132
|
|
|
124
133
|
When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable or aborted, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation.
|
|
125
134
|
|
|
126
|
-
# Continuable delegation and workflow execution are official model-facing
|
|
127
|
-
# capabilities. Their registries and providers stay in the host composition.
|
|
128
135
|
- id: delegation
|
|
129
136
|
name: cordis:group
|
|
130
137
|
group: true
|
|
@@ -134,33 +141,26 @@
|
|
|
134
141
|
- id: tool-subagent-control
|
|
135
142
|
name: '@deepseek-ai/dsh-tool-subagent-control'
|
|
136
143
|
|
|
137
|
-
- id: tool-subagent-list-agents
|
|
138
|
-
name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'
|
|
139
|
-
|
|
140
144
|
- id: tool-subagent
|
|
141
145
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
142
146
|
config:
|
|
143
147
|
provider: spawn
|
|
144
148
|
toolName: subagent
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
modelSelection: true
|
|
150
|
+
modelDiscovery: true
|
|
147
151
|
|
|
148
152
|
- id: tool-subagent-fork
|
|
149
153
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
150
154
|
config:
|
|
151
155
|
provider: fork
|
|
152
156
|
toolName: subagent_fork
|
|
153
|
-
backgroundMode: continuable
|
|
154
157
|
|
|
155
|
-
# Optional providers remain disabled until their matching Bundle is
|
|
156
|
-
# installed in the host profile.
|
|
157
158
|
- id: tool-subagent-codex
|
|
158
159
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
159
160
|
disabled: true
|
|
160
161
|
config:
|
|
161
162
|
provider: codex
|
|
162
163
|
toolName: subagent_codex
|
|
163
|
-
backgroundMode: one-shot
|
|
164
164
|
maxDepth: provider-managed
|
|
165
165
|
|
|
166
166
|
- id: tool-subagent-claude-code
|
|
@@ -169,11 +169,10 @@
|
|
|
169
169
|
config:
|
|
170
170
|
provider: claude-code
|
|
171
171
|
toolName: subagent_claude_code
|
|
172
|
-
backgroundMode: one-shot
|
|
173
172
|
maxDepth: provider-managed
|
|
174
173
|
|
|
175
174
|
- id: workflow-worker-thread
|
|
176
|
-
name: '@deepseek-ai/dsh-workflow-
|
|
175
|
+
name: '@deepseek-ai/dsh-workflow-ptc'
|
|
177
176
|
config:
|
|
178
177
|
provider: spawn
|
|
179
178
|
|
|
@@ -186,8 +185,6 @@
|
|
|
186
185
|
subagentProvider: spawn
|
|
187
186
|
maxRounds: 64
|
|
188
187
|
|
|
189
|
-
# These official tools provide the interactive question surface and the
|
|
190
|
-
# durable whole-list task view alongside Codex-compatible update_plan.
|
|
191
188
|
- id: tool-ask-user
|
|
192
189
|
name: '@deepseek-ai/dsh-tool-ask-user'
|
|
193
190
|
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Offline registry/native-dispatch benchmark. No model requests, file mutations, or OS commands.
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { performance } from 'node:perf_hooks'
|
|
4
|
+
import { writeFileSync } from 'node:fs'
|
|
5
|
+
import { cpus, platform, arch } from 'node:os'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
8
|
+
import { createScope, scopeTarget } from '@deepseek-ai/dsh-scope'
|
|
9
|
+
import SessionStore, { SessionId } from '@deepseek-ai/dsh-session'
|
|
10
|
+
import SessionProjections from '@deepseek-ai/dsh-session-projection'
|
|
11
|
+
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
|
12
|
+
import Tools from '@deepseek-ai/dsh-tools'
|
|
13
|
+
import * as NativeExecutor from '@deepseek-ai/dsh-tool-executor-native'
|
|
14
|
+
import * as FsTools from '@deepseek-ai/dsh-tool-fs'
|
|
15
|
+
import * as SearchTools from '@deepseek-ai/dsh-tool-fs-search'
|
|
16
|
+
import * as PwshTool from '@deepseek-ai/dsh-tool-pwsh'
|
|
17
|
+
import * as TodoTool from '@deepseek-ai/dsh-tool-todo'
|
|
18
|
+
import { getEncoding } from 'js-tiktoken'
|
|
19
|
+
import ToolPolicy from '../lib/types/entries/tool-policy.js'
|
|
20
|
+
import { registerCodexExecAndPlan } from '../lib/types/entries/index.js'
|
|
21
|
+
import { rewriteCodexResponsesBody } from '../lib/types/responses/wire-rewrite.js'
|
|
22
|
+
|
|
23
|
+
const samples = Number(process.env.BENCH_SAMPLES ?? 1200)
|
|
24
|
+
assert(Number.isSafeInteger(samples) && samples >= 100 && samples <= 10000)
|
|
25
|
+
const root = new Context()
|
|
26
|
+
const cwd = fileURLToPath(new URL('../', import.meta.url))
|
|
27
|
+
const presetIdentities = new WeakMap()
|
|
28
|
+
const agents = new Map()
|
|
29
|
+
let serial = 0
|
|
30
|
+
const probeName = '__tool_policy_benchmark_probe'
|
|
31
|
+
const identities = ['native', 'stacked', 'balanced', 'minimal', 'shadow']
|
|
32
|
+
const labels = {
|
|
33
|
+
native: '原生工具', stacked: '原生与 Codex 直接叠加',
|
|
34
|
+
balanced: '保留文件工具,替换执行与计划', minimal: '极简对照(非推荐)', shadow: '同名实现替换对照',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function summary(values) {
|
|
38
|
+
const sorted = [...values].sort((a, b) => a - b)
|
|
39
|
+
return { samples: values.length, medianUs: sorted[Math.floor(sorted.length / 2)], p95Us: sorted[Math.floor(sorted.length * .95)], meanUs: values.reduce((a, b) => a + b, 0) / values.length }
|
|
40
|
+
}
|
|
41
|
+
async function measure(profiles, key, task, count = samples) {
|
|
42
|
+
for (let i = 0; i < 80; i++) for (const profile of profiles) await task(profile, i)
|
|
43
|
+
const values = new Map(profiles.map(profile => [profile.id, []]))
|
|
44
|
+
for (let i = 0; i < count; i++) for (const profile of profiles) {
|
|
45
|
+
const start = performance.now()
|
|
46
|
+
await task(profile, i)
|
|
47
|
+
values.get(profile.id).push((performance.now() - start) * 1000)
|
|
48
|
+
}
|
|
49
|
+
for (const profile of profiles) profile.timings[key] = summary(values.get(profile.id))
|
|
50
|
+
}
|
|
51
|
+
const probe = {
|
|
52
|
+
name: probeName, description: 'Internal constant-time benchmark probe; excluded from schema token totals.',
|
|
53
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
54
|
+
output: { schema: { type: 'object', properties: { ok: { type: 'boolean' } }, required: ['ok'], additionalProperties: false }, render: value => JSON.stringify(value) },
|
|
55
|
+
isConcurrencySafe: () => true,
|
|
56
|
+
execute: async () => ({ ok: true }),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Capability facts match a confining Windows composition. No provider body is executed.
|
|
61
|
+
root.provide('fs', { sandboxMode: 'workspace-write' })
|
|
62
|
+
root.provide('shell', { sandboxMode: 'workspace-write', resolve: value => value, execute: async () => { throw new Error('OS execution is outside this benchmark') } })
|
|
63
|
+
root.provide('sandboxPolicy', { resolve: () => ({ mode: 'workspace-write', workspaceRoots: [cwd] }) })
|
|
64
|
+
root.provide('subprocess', {})
|
|
65
|
+
root.provide('shellEnv', { collect: () => ({}) })
|
|
66
|
+
root.provide('workingDirectory', { get: () => cwd, defaultDirectory: cwd })
|
|
67
|
+
root.provide('agents', { list: () => [...agents.values()], get: id => agents.get(id) })
|
|
68
|
+
root.provide('agentPresets', {
|
|
69
|
+
composedPreset: ctx => presetIdentities.get(ctx),
|
|
70
|
+
presetForSession: session => [...agents.values()].find(agent => agent.session === session)?.preset,
|
|
71
|
+
})
|
|
72
|
+
await root.plugin(SessionStore)
|
|
73
|
+
await root.plugin(SessionProjections)
|
|
74
|
+
await root.plugin(SystemPrompt, {})
|
|
75
|
+
await root.plugin(Tools)
|
|
76
|
+
await root.plugin(NativeExecutor)
|
|
77
|
+
|
|
78
|
+
const tools = root.get('tools')
|
|
79
|
+
const systemPrompt = root.get('systemPrompt')
|
|
80
|
+
const sessions = root.get('sessions')
|
|
81
|
+
const presetKey = {}
|
|
82
|
+
const preset = createScope(root, presetKey)
|
|
83
|
+
await preset.ctx.plugin(FsTools, { readImage: false, applyPatch: true })
|
|
84
|
+
await preset.ctx.plugin(SearchTools, { sampleOverCapGlobResults: false })
|
|
85
|
+
await preset.ctx.plugin(PwshTool, {})
|
|
86
|
+
await preset.ctx.plugin(TodoTool, { allowParallelInProgress: true })
|
|
87
|
+
preset.ctx.get('tools').register(probe)
|
|
88
|
+
const originalFiles = ['read', 'write', 'edit', 'apply_patch', 'glob', 'grep'].map(name => [name, tools.get(name, presetKey)])
|
|
89
|
+
for (const [name, definition] of originalFiles) assert(definition, `missing native tool ${name}`)
|
|
90
|
+
assert(tools.get('pwsh', presetKey))
|
|
91
|
+
assert(tools.get('todo_write', presetKey))
|
|
92
|
+
|
|
93
|
+
await root.plugin(ToolPolicy, { rules: [
|
|
94
|
+
{ preset: 'balanced', replaceShell: true, replacePlan: true },
|
|
95
|
+
{ preset: 'minimal', allow: ['pwsh', 'todo_write', 'apply_patch', probeName], replaceShell: true, replacePlan: true },
|
|
96
|
+
] })
|
|
97
|
+
|
|
98
|
+
async function newAgent(id) {
|
|
99
|
+
const session = sessions.create(SessionId(`bench-${id}-${++serial}`), { meta: { cwd } })
|
|
100
|
+
const agent = { id: session.id, session, preset: id, status: 'idle', options: { provider: 'benchmark', model: 'gpt-5.4' } }
|
|
101
|
+
const scope = createScope(root, agent, { parent: presetKey })
|
|
102
|
+
agent.ctx = scope.ctx
|
|
103
|
+
presetIdentities.set(agent.ctx, id)
|
|
104
|
+
agents.set(agent.id, agent)
|
|
105
|
+
const started = performance.now()
|
|
106
|
+
await root.serial(scopeTarget(agent, agent), 'agent/created', { agent, source: 'startup' })
|
|
107
|
+
const attachUs = (performance.now() - started) * 1000
|
|
108
|
+
return { agent, scope, attachUs, async dispose() { await scope.dispose(); agents.delete(agent.id) } }
|
|
109
|
+
}
|
|
110
|
+
const profiles = []
|
|
111
|
+
for (const id of identities) {
|
|
112
|
+
const handle = await newAgent(id)
|
|
113
|
+
const { agent } = handle
|
|
114
|
+
if (id === 'stacked') registerCodexExecAndPlan(agent.ctx)
|
|
115
|
+
if (id === 'shadow') agent.ctx.get('tools').register({ ...probe, execute: async () => ({ ok: true }) })
|
|
116
|
+
const signal = new AbortController().signal
|
|
117
|
+
const admission = await tools.resolve({ agent, modelSelection: agent.options, signal })
|
|
118
|
+
const schemas = tools.schemas(agent, admission).filter(tool => tool.name !== probeName)
|
|
119
|
+
const assembled = await systemPrompt.assemble({ scope: agent, toolSet: admission })
|
|
120
|
+
const profile = { id, label: labels[id], handle, agent, signal, admission, schemas, assembled, timings: {} }
|
|
121
|
+
if (id === 'balanced') {
|
|
122
|
+
for (const [name, definition] of originalFiles) assert.equal(tools.get(name, agent), definition, `file tool changed: ${name}`)
|
|
123
|
+
assert.equal(tools.executable('pwsh', agent, admission), undefined)
|
|
124
|
+
assert.equal(tools.executable('todo_write', agent, admission), undefined)
|
|
125
|
+
assert(schemas.some(tool => tool.name === 'exec_command'))
|
|
126
|
+
assert(schemas.some(tool => tool.name === 'update_plan'))
|
|
127
|
+
}
|
|
128
|
+
profiles.push(profile)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
await measure(profiles, 'resolveAndSchemas', async profile => {
|
|
132
|
+
const set = await tools.resolve({ agent: profile.agent, modelSelection: profile.agent.options, signal: profile.signal })
|
|
133
|
+
tools.schemas(profile.agent, set)
|
|
134
|
+
set.dispose()
|
|
135
|
+
})
|
|
136
|
+
await measure(profiles, 'assemble', profile => systemPrompt.assemble({ scope: profile.agent, toolSet: profile.admission }), Math.min(samples, 600))
|
|
137
|
+
await measure(profiles, 'nativeNoIoDispatch', async (profile, i) => {
|
|
138
|
+
const batch = await tools.execute({ agent: profile.agent, signal: profile.signal, toolSet: profile.admission,
|
|
139
|
+
calls: [{ type: 'tool-call', id: `benchmark-${i}`, name: probeName, arguments: '{}' }] })
|
|
140
|
+
assert.equal(batch.results[0].result.isError, false)
|
|
141
|
+
})
|
|
142
|
+
const history = Array.from({ length: 16 }, (_, i) => [
|
|
143
|
+
{ type: 'function_call', call_id: `patch-${i}`, name: 'apply_patch', arguments: JSON.stringify({ input: '*** Begin Patch\n*** Add File: sample.txt\n+sample\n*** End Patch' }) },
|
|
144
|
+
{ type: 'function_call_output', call_id: `patch-${i}`, output: 'Success.' },
|
|
145
|
+
]).flat()
|
|
146
|
+
for (const profile of profiles) profile.wireInput = { model: 'gpt-5.4', input: history, tools: profile.schemas.map(tool => ({ type: 'function', ...tool })) }
|
|
147
|
+
await measure(profiles, 'rewrite16PatchHistoryCalls', profile => { rewriteCodexResponsesBody(profile.wireInput) })
|
|
148
|
+
|
|
149
|
+
const attach = new Map(identities.map(id => [id, []]))
|
|
150
|
+
for (let i = 0; i < 60; i++) for (const id of identities) {
|
|
151
|
+
const handle = await newAgent(id)
|
|
152
|
+
if (i >= 10) attach.get(id).push(handle.attachUs)
|
|
153
|
+
await handle.dispose()
|
|
154
|
+
}
|
|
155
|
+
// Token counting is outside timing loops. This is a reference encoding, not provider billing.
|
|
156
|
+
const tokenizer = getEncoding('o200k_base')
|
|
157
|
+
const stats = value => {
|
|
158
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value)
|
|
159
|
+
return { utf8Bytes: Buffer.byteLength(text), o200kBaseTokens: tokenizer.encode(text).length }
|
|
160
|
+
}
|
|
161
|
+
const result = {
|
|
162
|
+
generatedAt: new Date().toISOString(), runtimeVersion: '0.2.2-rc.1', node: process.version,
|
|
163
|
+
platform: platform(), arch: arch(), cpu: cpus()[0]?.model, samples,
|
|
164
|
+
methodology: {
|
|
165
|
+
setup: 'Real Cordis scopes, ToolsService, native executor, official FS/search/pwsh/todo tool registrations and the actual tool-policy plugin; lightweight Agent owners and preset identity table, no AgentLoop/model/OS or file I/O.',
|
|
166
|
+
baseline: 'Eight native capabilities: read/write/edit/apply_patch/glob/grep/pwsh/todo_write. read_image excluded because no attachment store is mounted. All other Harness tools are held outside this subset.',
|
|
167
|
+
probe: 'Every timing case also carries the same constant-time probe, excluded from reported model schema totals. Dispatch is unlogged outside a model step; not a full AgentLoop/logging benchmark.',
|
|
168
|
+
timing: '80 warm-ups; cases interleaved per sample; performance.now microseconds. Attach: 10 warm-ups + 50 samples. Assembly capped at 600 samples.',
|
|
169
|
+
tokens: 'JSON schema/body and assembled section text counted with js-tiktoken o200k_base. Not a claim about gpt-6.1-sol billing, TTFT, cache hits, or task success rate.',
|
|
170
|
+
wire: 'Illustrative Responses function-tool mapping plus actual plugin rewrite with 16 correlated apply_patch call/results; no HTTP request.',
|
|
171
|
+
limits: 'No React rendering, model latency, filesystem/OS process timing, permission interaction latency or process-memory savings measured.',
|
|
172
|
+
},
|
|
173
|
+
profiles: profiles.map(profile => ({
|
|
174
|
+
id: profile.id, label: profile.label, tools: profile.schemas.map(tool => tool.name).sort(),
|
|
175
|
+
schema: stats(profile.schemas), promptSections: stats(profile.assembled.sections.map(section => section.text).join('\n\n')),
|
|
176
|
+
illustrativeWire: stats(rewriteCodexResponsesBody(profile.wireInput)),
|
|
177
|
+
timings: { ...profile.timings, agentCreatedListener: summary(attach.get(profile.id)) },
|
|
178
|
+
})),
|
|
179
|
+
}
|
|
180
|
+
const output = new URL('../docs/tool-policy-benchmark.json', import.meta.url)
|
|
181
|
+
writeFileSync(output, JSON.stringify(result, null, 2) + '\n')
|
|
182
|
+
console.log(JSON.stringify(result, null, 2))
|
|
183
|
+
for (const profile of profiles) { profile.admission.dispose(); await profile.handle.dispose() }
|
|
184
|
+
} finally {
|
|
185
|
+
await root.fiber.dispose()
|
|
186
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generate the public bundle declaration from presets/codex-hybrid.
|
|
2
|
+
import { writeFileSync } from 'node:fs'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { stringify } from 'yaml'
|
|
5
|
+
import { desktopCodexHybridPreset } from '../lib/types/presets/desktop-preset.js'
|
|
6
|
+
|
|
7
|
+
const hybridPreset = desktopCodexHybridPreset(fileURLToPath(new URL('../presets/codex-hybrid/', import.meta.url)))
|
|
8
|
+
const patch = [{ insert: [
|
|
9
|
+
{ id: 'codex', name: '@shuind/dsh-codex-harness/preferences' },
|
|
10
|
+
{ id: 'codex-tool-policy', name: '@shuind/dsh-codex-harness/tool-policy', config: { rules: [] } },
|
|
11
|
+
{ id: 'preset-codex-hybrid', name: '@deepseek-ai/dsh-agent-preset', config: hybridPreset },
|
|
12
|
+
{
|
|
13
|
+
id: 'codex-client', name: '@shuind/dsh-codex-harness',
|
|
14
|
+
config: { globalEnhancements: true, codexCore: false },
|
|
15
|
+
},
|
|
16
|
+
] }]
|
|
17
|
+
writeFileSync(new URL('../cordis.patch.yml', import.meta.url),
|
|
18
|
+
'# Generated by scripts/build-preset.mjs; edit presets/codex-hybrid or src/presets/desktop-preset.ts.\n'
|
|
19
|
+
+ stringify(patch, { lineWidth: 0 }), 'utf8')
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Remove only this package's generated output before emitting a fresh bundle.
|
|
2
|
+
import { rmSync } from 'node:fs'
|
|
3
|
+
import { basename, dirname, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
const root = resolve(fileURLToPath(new URL('../', import.meta.url)))
|
|
7
|
+
const output = resolve(root, 'lib')
|
|
8
|
+
if (dirname(output) !== root || basename(output) !== 'lib') {
|
|
9
|
+
throw new Error(`Refusing to clean an unexpected output directory: ${output}`)
|
|
10
|
+
}
|
|
11
|
+
rmSync(output, { recursive: true, force: true })
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** Client-only inference used while the host activity projection frame is in flight. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The legacy conversation slice is no longer part of the current Session
|
|
5
|
+
* snapshot. Keep this fallback structural so both generations can load without
|
|
6
|
+
* depending on the removed dsh-client-runtime package.
|
|
7
|
+
*/
|
|
8
|
+
export interface ActivitySessionSnapshot {
|
|
9
|
+
readonly running: boolean
|
|
10
|
+
readonly partial?: { readonly turn: number; readonly replyStartedAt?: number | undefined } | null | undefined
|
|
11
|
+
readonly runningCalls?: readonly unknown[] | undefined
|
|
12
|
+
readonly turnTimings?: ReadonlyMap<number, { readonly startTime: number; readonly endTime?: number | undefined }> | undefined
|
|
13
|
+
readonly chat?: {
|
|
14
|
+
readonly timeline: { readonly turns: ReadonlyMap<number, { readonly steps: readonly { readonly step: number; readonly end?: unknown }[] }> }
|
|
15
|
+
readonly nodes: { values(): Iterable<{ readonly kind: string; readonly data: unknown }> }
|
|
16
|
+
} | undefined
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CodexModelActivity = {
|
|
20
|
+
activity: 'requesting-model' | 'model-reply'
|
|
21
|
+
startedAt: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Equality for selector hooks, whose default is reference identity. */
|
|
25
|
+
export function sameModelActivity(
|
|
26
|
+
left: CodexModelActivity | undefined,
|
|
27
|
+
right: CodexModelActivity | undefined,
|
|
28
|
+
): boolean {
|
|
29
|
+
return left?.activity === right?.activity && left?.startedAt === right?.startedAt
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Infer the request-phase clock from the existing conversation snapshot. */
|
|
33
|
+
export function awaitingModelStartedAt(snapshot: ActivitySessionSnapshot): number | undefined {
|
|
34
|
+
if (!snapshot.running || (snapshot.runningCalls?.length ?? 0) > 0) return undefined
|
|
35
|
+
if (snapshot.turnTimings === undefined) return undefined
|
|
36
|
+
let latest: number | undefined
|
|
37
|
+
for (const timing of snapshot.turnTimings.values()) {
|
|
38
|
+
if (timing.endTime === undefined) latest = timing.startTime
|
|
39
|
+
}
|
|
40
|
+
return latest
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Infer the first non-empty model token timestamp from the current snapshot. */
|
|
44
|
+
export function modelReplyStartedAt(snapshot: ActivitySessionSnapshot): number | undefined {
|
|
45
|
+
if (!snapshot.running || (snapshot.runningCalls?.length ?? 0) > 0) return undefined
|
|
46
|
+
if (snapshot.turnTimings === undefined) return undefined
|
|
47
|
+
let openTurn: { turn: number; startTime: number } | undefined
|
|
48
|
+
for (const [turn, timing] of snapshot.turnTimings) {
|
|
49
|
+
if (timing.endTime === undefined) openTurn = { turn, startTime: timing.startTime }
|
|
50
|
+
}
|
|
51
|
+
if (openTurn === undefined) return undefined
|
|
52
|
+
if (snapshot.partial !== undefined && snapshot.partial !== null && snapshot.partial.turn === openTurn.turn) {
|
|
53
|
+
const partialReplyStartedAt = snapshot.partial.replyStartedAt
|
|
54
|
+
if (partialReplyStartedAt !== undefined) return partialReplyStartedAt
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A non-streaming adapter has no partial row. The assembled Chat view still
|
|
58
|
+
// carries the reply boundary, but only accept it for the currently open step
|
|
59
|
+
// so an earlier tool step in the same turn cannot mask a new request.
|
|
60
|
+
const chat = snapshot.chat
|
|
61
|
+
const turn = chat?.timeline.turns.get(openTurn.turn)
|
|
62
|
+
const step = turn?.steps.findLast(candidate => candidate.end === undefined)
|
|
63
|
+
if (step === undefined) return undefined
|
|
64
|
+
let matched: number | undefined
|
|
65
|
+
for (const node of chat?.nodes.values() ?? []) {
|
|
66
|
+
if (node.kind !== 'assistant-step') continue
|
|
67
|
+
const data = node.data as { turn?: unknown; step?: unknown; replyStartedAt?: unknown }
|
|
68
|
+
if (data.turn === openTurn.turn && data.step === step.step && typeof data.replyStartedAt === 'number') {
|
|
69
|
+
matched = data.replyStartedAt
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return matched
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Infer the two-phase model activity from the current client snapshot. */
|
|
76
|
+
export function modelActivity(snapshot: ActivitySessionSnapshot): CodexModelActivity | undefined {
|
|
77
|
+
const startedAt = awaitingModelStartedAt(snapshot)
|
|
78
|
+
if (startedAt === undefined) return undefined
|
|
79
|
+
const replyStartedAt = modelReplyStartedAt(snapshot)
|
|
80
|
+
return replyStartedAt === undefined
|
|
81
|
+
? { activity: 'requesting-model', startedAt }
|
|
82
|
+
: { activity: 'model-reply', startedAt: replyStartedAt }
|
|
83
|
+
}
|