@shuind/dsh-codex-harness 0.2.21 → 0.2.32-dsh-v0.2.2-rc.1
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 +121 -0
- package/README.md +48 -38
- package/RELEASE.md +61 -0
- package/assets/codex.svg +5 -0
- package/cordis.patch.yml +150 -6
- package/docs/preset-library.md +39 -23
- package/docs/tool-policy-benchmark.json +310 -0
- package/docs/tool-policy.md +144 -0
- package/lib/client.js +1639 -111
- package/lib/compaction.js +17 -2
- package/lib/index.js +799 -188
- package/lib/installer.js +50 -6
- package/lib/preferences.js +111 -0
- package/lib/tool-policy.js +2235 -0
- package/lib/typert.js +57 -10
- package/lib/types/activity.d.ts +1 -1
- package/lib/types/activity.js +50 -14
- package/lib/types/client/activity.d.ts +33 -9
- package/lib/types/client/desktop.d.ts +43 -0
- package/lib/types/client/desktop.js +121 -0
- package/lib/types/client/entry.d.ts +10 -0
- package/lib/types/client/entry.js +12 -0
- package/lib/types/client/index.d.ts +109 -19
- package/lib/types/client/index.js +21 -40
- package/lib/types/client/policy-drafts.d.ts +25 -0
- package/lib/types/client/policy-drafts.js +47 -0
- package/lib/types/client/preset-copy.d.ts +1 -0
- package/lib/types/client/preset-copy.js +2 -0
- package/lib/types/client/preset-manager.d.ts +12 -2
- package/lib/types/client/preset-manager.js +70 -25
- package/lib/types/client/preset-requests.d.ts +12 -0
- package/lib/types/client/preset-requests.js +101 -0
- package/lib/types/client/session.d.ts +6 -0
- package/lib/types/client/session.js +9 -0
- package/lib/types/client/tool-policy.d.ts +120 -0
- package/lib/types/client/tool-policy.js +394 -0
- package/lib/types/compaction.d.ts +3 -3
- package/lib/types/compaction.js +6 -2
- package/lib/types/desktop-preset.d.ts +20 -0
- package/lib/types/desktop-preset.js +39 -0
- package/lib/types/exec.d.ts +4 -0
- package/lib/types/exec.js +192 -66
- package/lib/types/host-settings.d.ts +4 -0
- package/lib/types/host-settings.js +13 -0
- package/lib/types/index.d.ts +20 -2
- package/lib/types/index.js +181 -68
- package/lib/types/installer.js +11 -2
- package/lib/types/preferences.d.ts +11 -0
- package/lib/types/preferences.js +16 -0
- package/lib/types/preset-editor-remote.d.ts +2 -0
- package/lib/types/preset-editor-remote.js +6 -2
- package/lib/types/preset-editor.d.ts +12 -7
- package/lib/types/preset-editor.js +43 -13
- package/lib/types/preset-prompt-catalog-schema.d.ts +16 -0
- package/lib/types/preset-prompt-catalog-schema.js +11 -0
- package/lib/types/preset-prompt-catalog.d.ts +21 -0
- package/lib/types/preset-prompt-catalog.js +192 -0
- package/lib/types/preset-prompt-contract.d.ts +22 -0
- package/lib/types/preset-prompt-contract.js +3 -0
- package/lib/types/preset-tool-catalog-schema.d.ts +38 -0
- package/lib/types/preset-tool-catalog-schema.js +28 -0
- package/lib/types/preset-tool-catalog.d.ts +5 -0
- package/lib/types/preset-tool-catalog.js +51 -0
- package/lib/types/prompt-sections.d.ts +1 -1
- package/lib/types/prompt-sections.js +9 -3
- package/lib/types/prompt.js +4 -2
- package/lib/types/remote.js +23 -8
- package/lib/types/settings.d.ts +3 -3
- package/lib/types/settings.js +3 -3
- package/lib/types/tool-capabilities.d.ts +32 -0
- package/lib/types/tool-capabilities.js +42 -0
- package/lib/types/tool-policy-contract.d.ts +60 -0
- package/lib/types/tool-policy-contract.js +26 -0
- package/lib/types/tool-policy.d.ts +171 -0
- package/lib/types/tool-policy.js +367 -0
- package/lib/types/typert.host.d.ts +2 -2
- package/lib/types/typert.host.js +12 -2
- package/locale/en.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 +375 -299
- package/scripts/benchmark-tool-policy.mjs +186 -0
- package/scripts/build-preset.mjs +19 -0
- package/scripts/clean-build.mjs +11 -0
- package/src/activity-types.ts +7 -0
- package/src/activity.ts +158 -0
- package/src/client/activity.ts +82 -0
- package/src/client/desktop.tsx +162 -0
- package/src/client/entry.tsx +16 -0
- package/src/client/index.tsx +972 -0
- package/src/client/policy-drafts.ts +56 -0
- package/src/client/preset-copy.ts +83 -0
- package/src/client/preset-manager.tsx +281 -0
- package/src/client/preset-requests.ts +113 -0
- package/src/client/session.ts +11 -0
- package/src/client/tool-policy.tsx +380 -0
- package/src/compact-command.ts +112 -0
- package/src/compaction.ts +190 -0
- package/src/context.ts +15 -0
- package/src/desktop-preset.ts +55 -0
- package/src/exec.ts +570 -0
- package/src/host-settings.ts +17 -0
- package/src/index.ts +1097 -0
- package/src/installer.ts +172 -0
- package/src/invariant.ts +34 -0
- package/src/patch.ts +258 -0
- package/src/preferences.ts +17 -0
- package/src/preset-contract.ts +85 -0
- package/src/preset-editor-remote.ts +41 -0
- package/src/preset-editor.ts +502 -0
- package/src/preset-prompt-catalog-schema.ts +10 -0
- package/src/preset-prompt-catalog.ts +191 -0
- package/src/preset-prompt-contract.ts +21 -0
- package/src/preset-tool-catalog-schema.ts +28 -0
- package/src/preset-tool-catalog.ts +51 -0
- package/src/prompt-sections.ts +33 -0
- package/src/prompt.ts +62 -0
- package/src/remote.ts +748 -0
- package/src/settings.ts +79 -0
- package/src/tool-capabilities.ts +76 -0
- package/src/tool-policy-contract.ts +76 -0
- package/src/tool-policy.ts +388 -0
- package/src/typert.host.ts +119 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +110 -0
- package/lib/types/preset-templates.d.ts +0 -36
- package/lib/types/preset-templates.js +0 -12
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** Codex compaction backend that honors the latest durable request capacity. */
|
|
2
|
+
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
4
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
5
|
+
import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic'
|
|
6
|
+
import type { CompactionResult, CompactionTrigger } from '@deepseek-ai/dsh-compaction'
|
|
7
|
+
import type { Session } from '@deepseek-ai/dsh-session'
|
|
8
|
+
import type { GenerateOptions } from '@deepseek-ai/dsh-llm'
|
|
9
|
+
import type {} from '@deepseek-ai/dsh-llm'
|
|
10
|
+
import { readHostSettings } from './host-settings.ts'
|
|
11
|
+
|
|
12
|
+
type LlmService = NonNullable<Context['llm']>
|
|
13
|
+
type CodexGenerateOptions = GenerateOptions & { contextWindow?: number }
|
|
14
|
+
|
|
15
|
+
/** Per-command compaction preference propagated into the LLM stream seam. */
|
|
16
|
+
export type CodexCompactionMode = 'remote' | 'local'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The main plugin entry and the compact-command subpath can be evaluated as
|
|
20
|
+
* separate bundles. Keep their async context carrier on the process global so
|
|
21
|
+
* an explicit command mode reaches the global llm/stream listener.
|
|
22
|
+
*/
|
|
23
|
+
const COMPACTION_MODE_KEY = Symbol.for('shuind.dsh-codex-harness.compaction-mode')
|
|
24
|
+
const COMPACTION_MODE = (() => {
|
|
25
|
+
const registry = globalThis as unknown as Record<PropertyKey, unknown>
|
|
26
|
+
const existing = registry[COMPACTION_MODE_KEY]
|
|
27
|
+
if (existing !== undefined) return existing as AsyncLocalStorage<CodexCompactionMode>
|
|
28
|
+
const storage = new AsyncLocalStorage<CodexCompactionMode>()
|
|
29
|
+
registry[COMPACTION_MODE_KEY] = storage
|
|
30
|
+
return storage
|
|
31
|
+
})()
|
|
32
|
+
|
|
33
|
+
/** Run one manual compaction with an explicit local/remote preference. */
|
|
34
|
+
export function runCodexCompactionMode<T>(
|
|
35
|
+
mode: CodexCompactionMode,
|
|
36
|
+
task: () => Promise<T>,
|
|
37
|
+
): Promise<T> {
|
|
38
|
+
return COMPACTION_MODE.run(mode, task)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Read the explicit preference for the current compaction stream, if any. */
|
|
42
|
+
export function codexCompactionMode(): CodexCompactionMode | undefined {
|
|
43
|
+
return COMPACTION_MODE.getStore()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const CODEX_SETTINGS_NAMESPACE = 'codex' as const
|
|
47
|
+
|
|
48
|
+
interface CodexSettings {
|
|
49
|
+
contextWindow?: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Codex context overrides apply only to GPT-compatible model routes. */
|
|
53
|
+
function isGptModel(model: string): boolean {
|
|
54
|
+
return /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface ConfiguredContextWindow {
|
|
58
|
+
/** Whether the settings service is available and therefore authoritative. */
|
|
59
|
+
available: boolean
|
|
60
|
+
/** The current explicit override; absent means use the model default. */
|
|
61
|
+
value?: number
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Read the live Codex capacity without requiring a custom LLM service API. */
|
|
65
|
+
function configuredContextWindow(ctx: Context): ConfiguredContextWindow {
|
|
66
|
+
const settings = ctx.get('settings') as { get?: unknown; describe?: unknown } | undefined
|
|
67
|
+
if (settings?.get === undefined && settings?.describe === undefined) return { available: false }
|
|
68
|
+
const value = readHostSettings<CodexSettings>(ctx, CODEX_SETTINGS_NAMESPACE)
|
|
69
|
+
return {
|
|
70
|
+
available: true,
|
|
71
|
+
...value?.contextWindow !== undefined
|
|
72
|
+
&& Number.isSafeInteger(value.contextWindow)
|
|
73
|
+
&& value.contextWindow > 0
|
|
74
|
+
? { value: value.contextWindow }
|
|
75
|
+
: {},
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Read an explicit capacity persisted in the request header when settings are unavailable. */
|
|
80
|
+
function requestContextWindow(session: Session, provider: string, model: string): number | undefined {
|
|
81
|
+
const config = session.requestHeader()?.config as {
|
|
82
|
+
provider?: unknown
|
|
83
|
+
model?: unknown
|
|
84
|
+
contextWindow?: unknown
|
|
85
|
+
} | undefined
|
|
86
|
+
if (config?.provider !== provider || config.model !== model) return undefined
|
|
87
|
+
const value = config.contextWindow
|
|
88
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Resolve the capacity currently in force for an active Codex compaction. */
|
|
92
|
+
function activeContextWindow(
|
|
93
|
+
ctx: Context,
|
|
94
|
+
activeSession: AsyncLocalStorage<Session>,
|
|
95
|
+
provider: string,
|
|
96
|
+
model: string,
|
|
97
|
+
): number | undefined {
|
|
98
|
+
const session = activeSession.getStore()
|
|
99
|
+
const requestContext = session?.requestContext()
|
|
100
|
+
const configured = isGptModel(model)
|
|
101
|
+
? configuredContextWindow(ctx)
|
|
102
|
+
: { available: false }
|
|
103
|
+
// A live setting must win before the old request header: automatic pressure
|
|
104
|
+
// runs before the next request rebuilds that header.
|
|
105
|
+
return configured.available
|
|
106
|
+
? configured.value
|
|
107
|
+
: (session === undefined ? undefined : requestContextWindow(session, provider, model))
|
|
108
|
+
?? (requestContext?.provider === provider && requestContext.model === model
|
|
109
|
+
? requestContext.contextWindow
|
|
110
|
+
: undefined)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Overlay capacity lookup and auxiliary summary requests for compaction. */
|
|
114
|
+
function withDurableContextCapacity(
|
|
115
|
+
llm: LlmService,
|
|
116
|
+
ctx: Context,
|
|
117
|
+
activeSession: AsyncLocalStorage<Session>,
|
|
118
|
+
): LlmService {
|
|
119
|
+
return new Proxy(llm, {
|
|
120
|
+
get(target, property) {
|
|
121
|
+
if (property === 'resolveModelInfo') {
|
|
122
|
+
return async (provider: string, model: string, signal?: AbortSignal) => {
|
|
123
|
+
const info = await target.resolveModelInfo(provider, model, signal)
|
|
124
|
+
const contextWindow = activeContextWindow(ctx, activeSession, provider, model)
|
|
125
|
+
if (contextWindow === undefined) return info
|
|
126
|
+
return {
|
|
127
|
+
...info,
|
|
128
|
+
context: { ...info.context, contextWindow },
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (property === 'stream') {
|
|
133
|
+
return (options: CodexGenerateOptions) => {
|
|
134
|
+
const contextWindow = activeContextWindow(ctx, activeSession, options.provider, options.model)
|
|
135
|
+
if (contextWindow === undefined || options.contextWindow === contextWindow) {
|
|
136
|
+
return target.stream(options)
|
|
137
|
+
}
|
|
138
|
+
return target.stream({ ...options, contextWindow } as GenerateOptions)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const value = Reflect.get(target, property, target)
|
|
142
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
143
|
+
},
|
|
144
|
+
}) as LlmService
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Keep the upstream compaction policy, retention, overflow recovery, and
|
|
149
|
+
* transaction implementation intact. The scoped LLM seam changes only the
|
|
150
|
+
* context metadata returned during a pressure check.
|
|
151
|
+
*/
|
|
152
|
+
export default class CodexCompactionEngine extends BasicCompactionEngine {
|
|
153
|
+
static override inject = BasicCompactionEngine.inject
|
|
154
|
+
static override Config = BasicCompactionEngine.Config
|
|
155
|
+
|
|
156
|
+
private readonly activeSession: AsyncLocalStorage<Session>
|
|
157
|
+
|
|
158
|
+
constructor(ctx: Context, config: ConstructorParameters<typeof BasicCompactionEngine>[1] = {}) {
|
|
159
|
+
const activeSession = new AsyncLocalStorage<Session>()
|
|
160
|
+
const llm = ctx.get('llm')
|
|
161
|
+
if (llm === undefined) throw new Error('codex compaction requires ctx.llm')
|
|
162
|
+
super(ctx.extend({ llm: withDurableContextCapacity(llm, ctx, activeSession) }), config)
|
|
163
|
+
this.activeSession = activeSession
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
override compactIfNeeded(
|
|
167
|
+
agent: Parameters<BasicCompactionEngine['compactIfNeeded']>[0],
|
|
168
|
+
trigger: CompactionTrigger,
|
|
169
|
+
signal: AbortSignal,
|
|
170
|
+
): Promise<CompactionResult | null> {
|
|
171
|
+
return this.activeSession.run(agent.session, () => super.compactIfNeeded(agent, trigger, signal))
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
override compactRegion(
|
|
175
|
+
...args: Parameters<BasicCompactionEngine['compactRegion']>
|
|
176
|
+
): Promise<CompactionResult> {
|
|
177
|
+
return this.activeSession.run(args[2].session, () => super.compactRegion(...args))
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
override compactNow(
|
|
181
|
+
agent: Parameters<BasicCompactionEngine['compactNow']>[0],
|
|
182
|
+
signal: AbortSignal,
|
|
183
|
+
sourceCommandId?: Parameters<BasicCompactionEngine['compactNow']>[2],
|
|
184
|
+
): Promise<CompactionResult | null> {
|
|
185
|
+
return this.activeSession.run(
|
|
186
|
+
agent.session,
|
|
187
|
+
() => super.compactNow(agent, signal, sourceCommandId),
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** User-selectable Codex context controls use whole K-token units. */
|
|
2
|
+
export const CODEX_CONTEXT_UNIT = 1_000
|
|
3
|
+
export const CODEX_CONTEXT_MAX = 1_000_000
|
|
4
|
+
export const CODEX_PRESET_ID = 'codex'
|
|
5
|
+
export const CODEX_COLLABORATION_PRESET_ID = 'codex-collaboration'
|
|
6
|
+
|
|
7
|
+
const CODEX_PRESET_IDS = new Set([
|
|
8
|
+
CODEX_PRESET_ID,
|
|
9
|
+
CODEX_COLLABORATION_PRESET_ID,
|
|
10
|
+
])
|
|
11
|
+
|
|
12
|
+
/** The bundled preset and legacy Codex sessions share the same Web controls. */
|
|
13
|
+
export function isCodexPresetId(value: string | undefined): boolean {
|
|
14
|
+
return value !== undefined && CODEX_PRESET_IDS.has(value)
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { parseDocument } from 'yaml'
|
|
4
|
+
|
|
5
|
+
export interface DesktopPresetRow {
|
|
6
|
+
id: string
|
|
7
|
+
name: string
|
|
8
|
+
group?: boolean
|
|
9
|
+
disabled?: boolean | { __jsExpr: string }
|
|
10
|
+
config?: Record<string, unknown> | DesktopPresetRow[]
|
|
11
|
+
isolate?: Record<string, boolean>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface DesktopPresetDefinition {
|
|
15
|
+
id: string
|
|
16
|
+
name?: string
|
|
17
|
+
description?: string
|
|
18
|
+
order?: number
|
|
19
|
+
plugins: DesktopPresetRow[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Keep expressions literal for the Desktop Loader, not YAML strings or eager eval. */
|
|
23
|
+
function readYaml(path: string): unknown {
|
|
24
|
+
const document = parseDocument(readFileSync(path, 'utf8'), {
|
|
25
|
+
customTags: [{
|
|
26
|
+
tag: 'tag:yaml.org,2002:js',
|
|
27
|
+
resolve: (expression: string) => ({ __jsExpr: expression }),
|
|
28
|
+
}],
|
|
29
|
+
})
|
|
30
|
+
if (document.errors.length) throw document.errors[0]
|
|
31
|
+
return document.toJS()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Convert the legacy file composition to Harness 0.2.2's declarative preset APIs. */
|
|
35
|
+
export function desktopCodexPreset(sourceDirectory: string): DesktopPresetDefinition {
|
|
36
|
+
const metadata = readYaml(join(sourceDirectory, 'preset.yml')) as Omit<DesktopPresetDefinition, 'id' | 'plugins'>
|
|
37
|
+
const plugins = readYaml(join(sourceDirectory, 'agent.cordis.yml')) as DesktopPresetRow[]
|
|
38
|
+
function adapt(rows: DesktopPresetRow[]): DesktopPresetRow[] {
|
|
39
|
+
// Child discovery now belongs to the control plugin's root export.
|
|
40
|
+
return rows.filter(row => row.name !== '@deepseek-ai/dsh-tool-subagent-control/list-agents').map(row => {
|
|
41
|
+
if (row.name === '@deepseek-ai/dsh-workflow-worker-thread') {
|
|
42
|
+
row.name = '@deepseek-ai/dsh-workflow-ptc'
|
|
43
|
+
}
|
|
44
|
+
if (row.name === '@deepseek-ai/dsh-tool-subagent' && row.config && !Array.isArray(row.config)) {
|
|
45
|
+
const { modelSelectionSettings, backgroundMode: _backgroundMode, ...config } = row.config
|
|
46
|
+
row.config = modelSelectionSettings === undefined ? config : {
|
|
47
|
+
...config, modelSelection: modelSelectionSettings, modelDiscovery: modelSelectionSettings,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (row.group && Array.isArray(row.config)) row.config = adapt(row.config)
|
|
51
|
+
return row
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
return { ...metadata, id: 'codex-collaboration', plugins: adapt(plugins) }
|
|
55
|
+
}
|