@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.
Files changed (200) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/README.md +38 -50
  3. package/RELEASE.md +61 -0
  4. package/assets/codex.svg +5 -0
  5. package/cordis.patch.yml +181 -6
  6. package/docs/preset-library.md +33 -23
  7. package/docs/tool-policy-benchmark.json +310 -0
  8. package/docs/tool-policy.md +148 -0
  9. package/lib/client.js +4774 -2416
  10. package/lib/compact-command.js +416 -0
  11. package/lib/compaction.js +141 -12
  12. package/lib/hybrid-executor.js +1196 -0
  13. package/lib/index.js +3658 -2334
  14. package/lib/preferences.js +117 -0
  15. package/lib/tool-policy.js +2422 -0
  16. package/lib/typert.js +86 -79
  17. package/lib/types/client/activity.d.ts +33 -9
  18. package/lib/types/client/activity.js +4 -3
  19. package/lib/types/client/desktop.d.ts +67 -0
  20. package/lib/types/client/desktop.js +229 -0
  21. package/lib/types/client/index.d.ts +207 -110
  22. package/lib/types/client/index.js +99 -492
  23. package/lib/types/client/policy-drafts.d.ts +25 -0
  24. package/lib/types/client/policy-drafts.js +47 -0
  25. package/lib/types/client/policy-locale.d.ts +260 -0
  26. package/lib/types/client/policy-locale.js +357 -0
  27. package/lib/types/client/preset-manager.d.ts +38 -10
  28. package/lib/types/client/preset-manager.js +235 -185
  29. package/lib/types/client/preset-requests.d.ts +12 -0
  30. package/lib/types/client/preset-requests.js +101 -0
  31. package/lib/types/client/tool-policy.d.ts +33 -0
  32. package/lib/types/client/tool-policy.js +336 -0
  33. package/lib/types/contracts/preset-editor-schema.d.ts +78 -0
  34. package/lib/types/contracts/preset-editor-schema.js +95 -0
  35. package/lib/types/{prompt.js → contracts/prompt.js} +13 -7
  36. package/lib/types/{settings.d.ts → contracts/settings.d.ts} +11 -4
  37. package/lib/types/{settings.js → contracts/settings.js} +22 -6
  38. package/lib/types/contracts/tool-policy-contract.d.ts +63 -0
  39. package/lib/types/contracts/tool-policy-contract.js +33 -0
  40. package/lib/types/contracts/ui-contracts.d.ts +92 -0
  41. package/lib/types/contracts/ui-contracts.js +83 -0
  42. package/lib/types/entries/client.d.ts +10 -0
  43. package/lib/types/entries/client.js +10 -0
  44. package/lib/types/{compact-command.d.ts → entries/compact-command.d.ts} +2 -0
  45. package/lib/types/entries/compact-command.js +176 -0
  46. package/lib/types/{compaction.d.ts → entries/compaction.d.ts} +15 -3
  47. package/lib/types/{compaction.js → entries/compaction.js} +47 -11
  48. package/lib/types/entries/hybrid-executor.d.ts +19 -0
  49. package/lib/types/entries/hybrid-executor.js +57 -0
  50. package/lib/types/entries/index.d.ts +66 -0
  51. package/lib/types/entries/index.js +192 -0
  52. package/lib/types/entries/preferences.d.ts +11 -0
  53. package/lib/types/entries/preferences.js +16 -0
  54. package/lib/types/entries/tool-policy.d.ts +97 -0
  55. package/lib/types/entries/tool-policy.js +158 -0
  56. package/lib/types/entries/typert.host.d.ts +23 -0
  57. package/lib/types/entries/typert.host.js +24 -0
  58. package/lib/types/hybrid/codex-hybrid-executor.d.ts +44 -0
  59. package/lib/types/hybrid/codex-hybrid-executor.js +257 -0
  60. package/lib/types/hybrid/hybrid-sdk.d.ts +13 -0
  61. package/lib/types/hybrid/hybrid-sdk.js +196 -0
  62. package/lib/types/hybrid/program-calls.d.ts +28 -0
  63. package/lib/types/hybrid/program-calls.js +193 -0
  64. package/lib/types/hybrid/subcall-scheduler.d.ts +90 -0
  65. package/lib/types/hybrid/subcall-scheduler.js +343 -0
  66. package/lib/types/policy/deferred-tools.d.ts +42 -0
  67. package/lib/types/policy/deferred-tools.js +264 -0
  68. package/lib/types/policy/overlay-installer.d.ts +12 -0
  69. package/lib/types/policy/overlay-installer.js +179 -0
  70. package/lib/types/policy/rule-resolver.d.ts +94 -0
  71. package/lib/types/policy/rule-resolver.js +114 -0
  72. package/lib/types/policy/tool-capabilities.d.ts +33 -0
  73. package/lib/types/policy/tool-capabilities.js +46 -0
  74. package/lib/types/{activity.d.ts → presets/activity.d.ts} +3 -5
  75. package/lib/types/{activity.js → presets/activity.js} +51 -27
  76. package/lib/types/presets/desktop-preset.d.ts +22 -0
  77. package/lib/types/presets/desktop-preset.js +43 -0
  78. package/lib/types/presets/preset-editor.d.ts +47 -0
  79. package/lib/types/presets/preset-editor.js +81 -0
  80. package/lib/types/presets/preset-prompt-catalog.d.ts +23 -0
  81. package/lib/types/presets/preset-prompt-catalog.js +215 -0
  82. package/lib/types/presets/preset-tool-catalog.d.ts +5 -0
  83. package/lib/types/presets/preset-tool-catalog.js +58 -0
  84. package/lib/types/presets/runtime-enhancements.d.ts +45 -0
  85. package/lib/types/presets/runtime-enhancements.js +349 -0
  86. package/lib/types/presets/small-window-compaction.d.ts +15 -0
  87. package/lib/types/presets/small-window-compaction.js +121 -0
  88. package/lib/types/responses/compact-checkpoint.d.ts +27 -0
  89. package/lib/types/responses/compact-checkpoint.js +257 -0
  90. package/lib/types/responses/fetch-transport.d.ts +16 -0
  91. package/lib/types/responses/fetch-transport.js +257 -0
  92. package/lib/types/responses/remote-compact.d.ts +13 -0
  93. package/lib/types/responses/remote-compact.js +319 -0
  94. package/lib/types/responses/sse-diagnostics.d.ts +9 -0
  95. package/lib/types/responses/sse-diagnostics.js +157 -0
  96. package/lib/types/responses/wire-rewrite.d.ts +35 -0
  97. package/lib/types/responses/wire-rewrite.js +237 -0
  98. package/lib/types/tools/exec-output.d.ts +58 -0
  99. package/lib/types/tools/exec-output.js +173 -0
  100. package/lib/types/tools/exec-plan-tools.d.ts +37 -0
  101. package/lib/types/tools/exec-plan-tools.js +265 -0
  102. package/lib/types/tools/exec-runner.d.ts +21 -0
  103. package/lib/types/tools/exec-runner.js +385 -0
  104. package/lib/types/tools/patch-tool.d.ts +16 -0
  105. package/lib/types/tools/patch-tool.js +258 -0
  106. package/lib/types/{patch.d.ts → tools/patch.d.ts} +1 -1
  107. package/lib/types/{patch.js → tools/patch.js} +96 -21
  108. package/locale/en.json +6 -0
  109. package/locale/hybrid-executor/en.json +6 -0
  110. package/locale/hybrid-executor/zh.json +6 -0
  111. package/locale/tool-policy/en.json +6 -0
  112. package/locale/tool-policy/zh.json +6 -0
  113. package/locale/zh.json +6 -0
  114. package/package.json +297 -299
  115. package/presets/{codex-collaboration → codex-hybrid}/agent.cordis.yml +45 -48
  116. package/presets/codex-hybrid/preset.yml +3 -0
  117. package/scripts/benchmark-tool-policy.mjs +186 -0
  118. package/scripts/build-preset.mjs +19 -0
  119. package/scripts/clean-build.mjs +11 -0
  120. package/src/client/activity.ts +83 -0
  121. package/src/client/desktop.tsx +276 -0
  122. package/src/client/index.tsx +391 -0
  123. package/src/client/policy-drafts.ts +56 -0
  124. package/src/client/policy-locale.ts +362 -0
  125. package/src/client/preset-manager.tsx +376 -0
  126. package/src/client/preset-requests.ts +113 -0
  127. package/src/client/tool-policy.tsx +402 -0
  128. package/src/contracts/preset-editor-schema.ts +110 -0
  129. package/src/contracts/prompt.ts +66 -0
  130. package/src/contracts/settings.ts +103 -0
  131. package/src/contracts/tool-policy-contract.ts +93 -0
  132. package/src/contracts/ui-contracts.ts +173 -0
  133. package/src/entries/client.tsx +14 -0
  134. package/src/entries/compact-command.ts +256 -0
  135. package/src/entries/compaction.ts +218 -0
  136. package/src/entries/hybrid-executor.ts +76 -0
  137. package/src/entries/index.ts +298 -0
  138. package/src/entries/preferences.ts +17 -0
  139. package/src/entries/tool-policy.ts +162 -0
  140. package/src/entries/typert.host.ts +29 -0
  141. package/src/hybrid/codex-hybrid-executor.ts +310 -0
  142. package/src/hybrid/hybrid-sdk.ts +217 -0
  143. package/src/hybrid/program-calls.ts +202 -0
  144. package/src/hybrid/subcall-scheduler.ts +446 -0
  145. package/src/policy/deferred-tools.ts +331 -0
  146. package/src/policy/overlay-installer.ts +191 -0
  147. package/src/policy/rule-resolver.ts +128 -0
  148. package/src/policy/tool-capabilities.ts +88 -0
  149. package/src/presets/activity.ts +146 -0
  150. package/src/presets/desktop-preset.ts +60 -0
  151. package/src/presets/preset-editor.ts +101 -0
  152. package/src/presets/preset-prompt-catalog.ts +221 -0
  153. package/src/presets/preset-tool-catalog.ts +58 -0
  154. package/src/presets/runtime-enhancements.ts +415 -0
  155. package/src/presets/small-window-compaction.ts +166 -0
  156. package/src/responses/compact-checkpoint.ts +264 -0
  157. package/src/responses/fetch-transport.ts +290 -0
  158. package/src/responses/remote-compact.ts +393 -0
  159. package/src/responses/sse-diagnostics.ts +156 -0
  160. package/src/responses/wire-rewrite.ts +261 -0
  161. package/src/tools/exec-output.ts +211 -0
  162. package/src/tools/exec-plan-tools.ts +307 -0
  163. package/src/tools/exec-runner.ts +445 -0
  164. package/src/tools/patch-tool.ts +331 -0
  165. package/src/tools/patch.ts +328 -0
  166. package/tsconfig.json +29 -0
  167. package/tsdown.config.ts +110 -0
  168. package/lib/installer.js +0 -237
  169. package/lib/invariant.js +0 -23
  170. package/lib/types/activity-types.d.ts +0 -6
  171. package/lib/types/activity-types.js +0 -3
  172. package/lib/types/client/preset-copy.d.ts +0 -42
  173. package/lib/types/client/preset-copy.js +0 -81
  174. package/lib/types/compact-command.js +0 -79
  175. package/lib/types/context.d.ts +0 -8
  176. package/lib/types/context.js +0 -14
  177. package/lib/types/exec.d.ts +0 -46
  178. package/lib/types/exec.js +0 -365
  179. package/lib/types/index.d.ts +0 -95
  180. package/lib/types/index.js +0 -738
  181. package/lib/types/installer.d.ts +0 -27
  182. package/lib/types/installer.js +0 -146
  183. package/lib/types/invariant.d.ts +0 -16
  184. package/lib/types/invariant.js +0 -22
  185. package/lib/types/preset-contract.d.ts +0 -69
  186. package/lib/types/preset-contract.js +0 -22
  187. package/lib/types/preset-editor-remote.d.ts +0 -30
  188. package/lib/types/preset-editor-remote.js +0 -37
  189. package/lib/types/preset-editor.d.ts +0 -69
  190. package/lib/types/preset-editor.js +0 -557
  191. package/lib/types/preset-templates.d.ts +0 -36
  192. package/lib/types/preset-templates.js +0 -12
  193. package/lib/types/prompt-sections.d.ts +0 -15
  194. package/lib/types/prompt-sections.js +0 -23
  195. package/lib/types/remote.d.ts +0 -40
  196. package/lib/types/remote.js +0 -683
  197. package/lib/types/typert.host.d.ts +0 -47
  198. package/lib/types/typert.host.js +0 -99
  199. package/presets/codex-collaboration/preset.yml +0 -3
  200. /package/lib/types/{prompt.d.ts → contracts/prompt.d.ts} +0 -0
@@ -0,0 +1,110 @@
1
+ import { defineConfig } from 'tsdown'
2
+
3
+ // DSH's browser module table owns these identities. Bundling either one would
4
+ // give slot components a second React runtime and make their Hooks invalid in
5
+ // the host renderer.
6
+ const CLIENT_EXTERNALS = new Set(['react', 'react/jsx-runtime', 'react-dom'])
7
+
8
+ /** Build the public entry point and invariant companion from TypeScript output. */
9
+ export default defineConfig([
10
+ {
11
+ entry: { preferences: 'lib/types/entries/preferences.js' },
12
+ outDir: 'lib',
13
+ format: ['esm'],
14
+ platform: 'node',
15
+ target: 'es2024',
16
+ fixedExtension: false,
17
+ dts: false,
18
+ clean: false,
19
+ },
20
+ {
21
+ entry: { index: 'lib/types/entries/index.js' },
22
+ outDir: 'lib',
23
+ format: ['esm'],
24
+ platform: 'node',
25
+ target: 'es2024',
26
+ fixedExtension: false,
27
+ dts: false,
28
+ clean: false,
29
+ },
30
+ {
31
+ entry: { 'tool-policy': 'lib/types/entries/tool-policy.js' },
32
+ outDir: 'lib',
33
+ format: ['esm'],
34
+ platform: 'node',
35
+ target: 'es2024',
36
+ fixedExtension: false,
37
+ dts: false,
38
+ clean: false,
39
+ },
40
+ {
41
+ entry: { 'hybrid-executor': 'lib/types/entries/hybrid-executor.js' },
42
+ outDir: 'lib',
43
+ format: ['esm'],
44
+ platform: 'node',
45
+ target: 'es2024',
46
+ fixedExtension: false,
47
+ dts: false,
48
+ clean: false,
49
+ },
50
+ {
51
+ entry: { 'compact-command': 'lib/types/entries/compact-command.js' },
52
+ outDir: 'lib',
53
+ format: ['esm'],
54
+ platform: 'node',
55
+ target: 'es2024',
56
+ fixedExtension: false,
57
+ dts: false,
58
+ clean: false,
59
+ },
60
+ {
61
+ entry: { compaction: 'lib/types/entries/compaction.js' },
62
+ outDir: 'lib',
63
+ format: ['esm'],
64
+ platform: 'node',
65
+ target: 'es2024',
66
+ fixedExtension: false,
67
+ dts: false,
68
+ clean: false,
69
+ },
70
+ {
71
+ entry: { typert: 'lib/types/entries/typert.host.js' },
72
+ outDir: 'lib',
73
+ format: ['esm'],
74
+ platform: 'node',
75
+ target: 'es2024',
76
+ fixedExtension: false,
77
+ dts: false,
78
+ clean: false,
79
+ },
80
+ {
81
+ entry: { client: 'lib/types/entries/client.js' },
82
+ outDir: 'lib',
83
+ // DSH loads client plugins through a closure factory, not as native ESM.
84
+ format: ['cjs'],
85
+ platform: 'browser',
86
+ target: 'es2022',
87
+ fixedExtension: false,
88
+ dts: false,
89
+ clean: false,
90
+ // React's browser CJS entry reads this Node-style global at runtime. The
91
+ // DSH client preset replaces it at build time before the bundle reaches
92
+ // the browser module loader.
93
+ define: {
94
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),
95
+ 'import.meta.env.MODE': JSON.stringify(process.env.NODE_ENV ?? 'production'),
96
+ 'import.meta.env': JSON.stringify({ MODE: process.env.NODE_ENV ?? 'production' }),
97
+ },
98
+ deps: {
99
+ neverBundle: (specifier: string) => CLIENT_EXTERNALS.has(specifier),
100
+ alwaysBundle: (specifier: string) => !CLIENT_EXTERNALS.has(specifier),
101
+ },
102
+ outputOptions: {
103
+ exports: 'named',
104
+ entryFileNames: 'client.js',
105
+ banner: 'window.__ModuleLoader__.load({ id: "@shuind/dsh-codex-harness", factory: (require) => {',
106
+ footer: 'return module.exports; } });',
107
+ intro: 'var module = { exports: {} }; var exports = module.exports;',
108
+ },
109
+ },
110
+ ])
package/lib/installer.js DELETED
@@ -1,237 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { dirname, join, resolve } from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import z from "@deepseek-ai/schemastery";
7
- //#region lib/types/context.js
8
- const CODEX_CONTEXT_MAX = 1e6;
9
- //#endregion
10
- //#region lib/types/prompt.js
11
- /** Default plugin-owned Codex operating prompt. */
12
- const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw`## General
13
-
14
- - When searching for text or files, prefer using rg or rg --files respectively because rg is much faster than alternatives like grep. If rg is not available, use the next best alternative.
15
-
16
- ## Editing constraints
17
-
18
- - Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.
19
- - Add succinct code comments that explain non-obvious code. Do not add comments that merely narrate assignments or control flow.
20
- - You may be in a dirty git worktree. Never revert existing changes you did not make unless the user explicitly requests it. If unrelated files are changed, leave them alone.
21
-
22
- ## Planning
23
-
24
- - Use update_plan for work with multiple meaningful steps. Keep the plan current as the task progresses.
25
- - Do not use a plan for a trivial one-step request.
26
-
27
- ## dsh session
28
-
29
- - The user and you share one workspace. Inspect the repository and every applicable AGENTS.md before editing.
30
-
31
- ## Task execution
32
-
33
- - Keep the user informed with concise progress updates and lead with the result.
34
-
35
- ## Presenting your work
36
-
37
- - Be concise, direct, friendly, and actionable.
38
- - For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
39
- - Do not dump large files into the conversation; refer to their paths.
40
- - Use plain text with short sections only when they improve scanability.
41
-
42
- ## Working principles
43
-
44
- - Actively establish the user's current context rather than relying on stale assumptions or prior context. Before committing to an approach that could materially shape the outcome or direction of the work, state the intended path and align it with the user; clarify any material uncertainty first. Then pursue the user's goal through the clearest, most effective path.
45
- - Keep only the essential logic and core actions. Don't explain or test what was removed or why something wasn't done, especially when writing documentation or communicating. Convey enough valuable information with as few words as possible.
46
- - Solve problems by thinking from first principles and at a higher level.
47
- `;
48
- /** Default deployment Persona template used by the Codex preset. */
49
- const DEFAULT_CODEX_PERSONA = String.raw`You are Codex, a coding agent based on the {{model}} model. Your working directory is {{cwd}}.`;
50
- /** Default DSH Core source-checkout guidance template. */
51
- const DEFAULT_DSH_CORE_SOURCE_PROMPT = String.raw`The DeepSeek Harness implementation checkout is at {{sourceRoot}}. The checkout location and current working directory are separate values and may differ; never infer the working directory from this path. Use pwd to determine the current working directory. Use this checkout only to inspect or extend DSH itself.`;
52
- /** Default DSH Web runtime guidance template. */
53
- const DEFAULT_DSH_CORE_WEB_PROMPT = [
54
- "You are interacting with the user through the DeepSeek Harness Web GUI at {{webUrl}}.",
55
- "When the user refers to \"this page\", \"this GUI\", or \"this app\" without naming another target, they mean this GUI.",
56
- "The browser provides no implicit DOM, route, or screenshot context.",
57
- "The client-plugin HMR receiver is active, but client-plugin changes reload without a refresh only while `pnpm run dev:web` is also running from this same checkout to rebuild their bundles; verify that watcher before promising automatic updates.",
58
- "Every other change - the apps/web shell and plain packages - requires rebuilding the affected Web artifacts and verifying this existing URL after a page refresh.",
59
- "Starting another server does not update this GUI.",
60
- "The apps/web Vite entry builds the shell but is not a standalone application because only dsh web injects window.__DSH_BOOT__.",
61
- "Do not start a replacement server unless the user asks; if one is needed, use a managed background job and verify its exact URL."
62
- ].join(" ");
63
- //#endregion
64
- //#region lib/types/settings.js
65
- /** Shared host-side Codex settings contract. */
66
- /** Live Codex controls shared by the Web UI and agent layer. */
67
- const CODEX_SETTINGS_NAMESPACE = "codex";
68
- /** Default settings exposed even before a Codex session is opened. */
69
- const CODEX_SETTINGS_ENTRY = {
70
- fast: false,
71
- fastModeControlEnabled: true,
72
- persona: DEFAULT_CODEX_PERSONA,
73
- harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
74
- webSurfacePrompt: DEFAULT_DSH_CORE_WEB_PROMPT,
75
- systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT,
76
- promptEnabled: true,
77
- terminalToolsEnabled: true,
78
- patchToolEnabled: true,
79
- planToolEnabled: true,
80
- hostedWebSearchEnabled: true,
81
- remoteCompactionEnabled: true,
82
- activityIndicatorEnabled: true
83
- };
84
- const CODEX_SETTINGS_SCHEMA = z.object({
85
- fast: z.boolean().default(false),
86
- fastModeControlEnabled: z.boolean().default(true),
87
- contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
88
- persona: z.string().default(DEFAULT_CODEX_PERSONA),
89
- harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
90
- webSurfacePrompt: z.string().default(DEFAULT_DSH_CORE_WEB_PROMPT),
91
- systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
92
- promptEnabled: z.boolean().default(true),
93
- terminalToolsEnabled: z.boolean().default(true),
94
- patchToolEnabled: z.boolean().default(true),
95
- planToolEnabled: z.boolean().default(true),
96
- hostedWebSearchEnabled: z.boolean().default(true),
97
- remoteCompactionEnabled: z.boolean().default(true),
98
- activityIndicatorEnabled: z.boolean().default(true)
99
- });
100
- //#endregion
101
- //#region lib/types/installer.js
102
- /** Install the user-visible Codex agent preset supplied by this bundle. */
103
- const PRESET_FILES = ["agent.cordis.yml", "preset.yml"];
104
- const MANAGED_SIGNATURE_FILE = ".dsh-codex-harness-managed";
105
- const BUNDLED_PRESET_ID = "codex-collaboration";
106
- const LEGACY_PRESET_ID = "codex";
107
- const SOURCE_PRESET_DIR = fileURLToPath(new URL("../presets/codex-collaboration/", import.meta.url));
108
- const LEGACY_PRESET_SIGNATURES = /* @__PURE__ */ new Set([
109
- "2f6222b6c9fed417d0f8fbfef9b221f0c9088c63347466219309c1c2ca2426bb",
110
- "40ae944220ca57daae93d1483d6cb6264e6847ed77ee84f38171c34c36f0598e",
111
- "c6a594797f7044c44c09254635b8381f20533cd26a4661239529dc44ec423d0c",
112
- "2c373798b9cadbda5fb377dab0d43ac5637263546a5a4fc1740752658fdec658",
113
- "a4062b59ad0e512e1b1b7e80ae56d8cde4efdaa5ba958364a17653ba1ff3c2ed",
114
- "16016e7f68ee61354de232151be5b6ad0cda1785183ca0c72f9d0946b6a1d6cd",
115
- "7f72b1bea9b30074788f05d20b841a797a5b29bb945dd1fb0597c8d03eb2b9b9",
116
- "6a6c8dc2e7a7dbc1ac30ce608a53c238f19066a786f951f9a295ada86e56ed9e"
117
- ]);
118
- const BUNDLED_PRESET_SIGNATURES = /* @__PURE__ */ new Set([
119
- "2a7ef181266e69275d25091adc74dd619af7c7d3577573887aaaecd2663e13c8",
120
- "d1de30f5c13049621b1c1ae3fb22d35b031797a4762638265822b0ff62749854",
121
- "b50e1d616f9b4188a33c0da0fe355478b7b75b615f3792c094e2b67995622cf4",
122
- "6132523d92893f6ae9214b30105e9cc1ba64854df6ca8a84213069eb6c38d286",
123
- "7957bc5e9b0f2fa0b74d2d8bae0d4ee153a2ba7bb430f5a848e700386cc7ce3f"
124
- ]);
125
- function dshHomePath(...segments) {
126
- const configured = process.env.DSH_HOME?.trim();
127
- const expanded = configured === void 0 || configured.length === 0 ? join(homedir(), ".dsh") : configured === "~" ? homedir() : configured.startsWith("~/") || configured.startsWith("~\\") ? join(homedir(), configured.slice(2)) : configured;
128
- return join(resolve(expanded), ...segments);
129
- }
130
- /** Bundle plugin name for the preset installer. */
131
- const name = "codex-preset-installer";
132
- const inject = ["settings"];
133
- function presetSignature(directory) {
134
- if (PRESET_FILES.some((file) => !existsSync(join(directory, file)))) return void 0;
135
- const hash = createHash("sha256");
136
- hash.update(readFileSync(join(directory, PRESET_FILES[0])));
137
- hash.update(Buffer.from([0]));
138
- hash.update(readFileSync(join(directory, PRESET_FILES[1])));
139
- return hash.digest("hex");
140
- }
141
- function stagePreset(targetDir, sourceDir, presetId) {
142
- const parentDir = dirname(targetDir);
143
- mkdirSync(parentDir, { recursive: true });
144
- const stagingDir = mkdtempSync(join(parentDir, `.${presetId}-`));
145
- try {
146
- for (const file of PRESET_FILES) copyFileSync(join(sourceDir, file), join(stagingDir, file));
147
- const signature = presetSignature(stagingDir);
148
- if (signature === void 0) throw new Error(`incomplete bundled preset: ${sourceDir}`);
149
- writeFileSync(join(stagingDir, MANAGED_SIGNATURE_FILE), `${signature}\n`);
150
- return stagingDir;
151
- } catch (error) {
152
- rmSync(stagingDir, {
153
- recursive: true,
154
- force: true
155
- });
156
- throw error;
157
- }
158
- }
159
- function installPreset(targetDir, sourceDir, presetId) {
160
- const stagingDir = stagePreset(targetDir, sourceDir, presetId);
161
- try {
162
- renameSync(stagingDir, targetDir);
163
- } catch (error) {
164
- if (!existsSync(targetDir)) throw error;
165
- rmSync(stagingDir, {
166
- recursive: true,
167
- force: true
168
- });
169
- }
170
- }
171
- function replacePreset(targetDir, sourceDir, presetId) {
172
- const stagingDir = stagePreset(targetDir, sourceDir, presetId);
173
- const backupDir = join(dirname(targetDir), `.${presetId}-backup-${randomUUID()}`);
174
- renameSync(targetDir, backupDir);
175
- try {
176
- renameSync(stagingDir, targetDir);
177
- rmSync(backupDir, {
178
- recursive: true,
179
- force: true
180
- });
181
- } catch (error) {
182
- if (existsSync(stagingDir)) rmSync(stagingDir, {
183
- recursive: true,
184
- force: true
185
- });
186
- if (!existsSync(targetDir)) renameSync(backupDir, targetDir);
187
- throw error;
188
- }
189
- }
190
- function hasMatchingManagedMarker(targetDir, signature) {
191
- const marker = join(targetDir, MANAGED_SIGNATURE_FILE);
192
- return existsSync(marker) && readFileSync(marker, "utf8").trim() === signature;
193
- }
194
- /**
195
- * Install or upgrade the single shipped Codex preset.
196
- *
197
- * The directory is committed with a staging rename so a failed copy cannot
198
- * leave a half-written preset that hides the mode from the roster. A known
199
- * shipped copy upgrades in place; any changed or unknown copy is preserved.
200
- *
201
- * @param targetDir - destination preset directory.
202
- * @param sourceDir - directory containing the packaged preset files.
203
- */
204
- function installCodexPreset(targetDir = dshHomePath(".agent-presets", BUNDLED_PRESET_ID), sourceDir = SOURCE_PRESET_DIR) {
205
- if (!existsSync(targetDir)) {
206
- installPreset(targetDir, sourceDir, BUNDLED_PRESET_ID);
207
- return;
208
- }
209
- const signature = presetSignature(targetDir);
210
- if (signature !== void 0 && (BUNDLED_PRESET_SIGNATURES.has(signature) || hasMatchingManagedMarker(targetDir, signature))) replacePreset(targetDir, sourceDir, BUNDLED_PRESET_ID);
211
- }
212
- /** Remove an unmodified copy of the retired second Codex mode. */
213
- function retireLegacyCodexPreset(targetDir = dshHomePath(".agent-presets", LEGACY_PRESET_ID), managedSignatures = LEGACY_PRESET_SIGNATURES) {
214
- if (!existsSync(targetDir)) return;
215
- const signature = presetSignature(targetDir);
216
- if (signature !== void 0 && managedSignatures.has(signature)) rmSync(targetDir, {
217
- recursive: true,
218
- force: true
219
- });
220
- }
221
- /** Install the preset during profile boot without changing the host tool catalog. */
222
- function apply(ctx) {
223
- try {
224
- ctx.settings.register(CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, { base: CODEX_SETTINGS_ENTRY });
225
- installCodexPreset();
226
- retireLegacyCodexPreset();
227
- } catch (error) {
228
- ctx.logger.warn(`dsh-codex: could not reconcile the Codex preset: ${String(error)}`);
229
- }
230
- }
231
- var installer_default = {
232
- name,
233
- inject,
234
- apply
235
- };
236
- //#endregion
237
- export { apply, installer_default as default, inject, installCodexPreset, name, retireLegacyCodexPreset };
package/lib/invariant.js DELETED
@@ -1,23 +0,0 @@
1
- //#region lib/types/invariant.js
2
- /**
3
- * Package-owned invariant companion for `@shuind/dsh-codex-harness`.
4
- * @module @shuind/dsh-codex-harness/invariant
5
- */
6
- const PACKAGE_NAME = "@shuind/dsh-codex-harness";
7
- /** Codex companion plugin name. */
8
- const name = "codex-invariant";
9
- /** Service required before the companion can reserve package ownership. */
10
- const inject = ["invariants"];
11
- /**
12
- * Codex has no independent lifecycle stream: its model-visible state is owned
13
- * by the tool registry and session projection services it consumes.
14
- */
15
- const install = () => {};
16
- /**
17
- * Register this package's invariant companion.
18
- * @param ctx - Cordis context carrying the invariant service.
19
- * @returns the installed registration's disposer after setup succeeds.
20
- */
21
- const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
22
- //#endregion
23
- export { apply, inject, name };
@@ -1,6 +0,0 @@
1
- /** Pure client/host-shared type for the Codex activity projection value. */
2
- export type CodexActivity = {
3
- activity: 'compaction' | 'requesting-model' | 'model-reply' | 'awaiting-model';
4
- startedAt: number;
5
- };
6
- //# sourceMappingURL=activity-types.d.ts.map
@@ -1,3 +0,0 @@
1
- /** Pure client/host-shared type for the Codex activity projection value. */
2
- export {};
3
- //# sourceMappingURL=activity-types.js.map
@@ -1,42 +0,0 @@
1
- export declare const presetEn: {
2
- readonly peConnectionError: "Could not connect to the local service. Retry loading; if the connection still fails, reconnect the page.";
3
- readonly peReadError: "Could not read this preset. Retry loading or refresh the preset list.";
4
- readonly peRetryRead: "Retry loading";
5
- readonly peReconnect: "Reconnect page";
6
- readonly peSystemPrompt: "System prompt sections";
7
- readonly peSectionsHint: "These templates contribute to this preset’s system prompt before the tools. Runtime variables, workspace instructions and plugin-provided guidance are assembled when the conversation runs.";
8
- readonly peDynamicPrompt: "This field is an expression; it is preserved without executing it in the editor.";
9
- readonly peDshSourcePrompt: "Tells the agent where the DSH source checkout is and keeps it separate from the current workspace. It is used when inspecting or extending DSH itself.";
10
- readonly peDshWebPrompt: "Tells the agent which Web page it is talking through, what “this page” means, and when Web changes need a rebuild or refresh.";
11
- readonly peSuppressed: "Not used";
12
- readonly peCompletePersona: "This preset uses Persona as its entire system prompt, so this section is excluded.";
13
- readonly peLoading: "Reading preset…";
14
- readonly peTitle: "Preset editor";
15
- readonly peHierarchy: "Codex mode and other presets are peers. Choose one to edit, or make an editable copy of a built-in preset first.";
16
- readonly peSelect: "Preset";
17
- readonly peSelectPlaceholder: "Choose a preset…";
18
- readonly peEditable: "This is an editable user preset.";
19
- readonly peBuiltinEdit: "Built-in presets are read-only. Create a copy to edit it.";
20
- readonly peCreateCopy: "Create editable copy";
21
- readonly peCodexSection: "Codex mode capabilities";
22
- readonly peAddCodex: "Add Codex capabilities to this preset";
23
- readonly peAddCodexHint: "Adds the Codex prompt, tools, hosted search, and remote compaction to this preset.";
24
- readonly peActivityGlobal: "Activity status is a global display setting and is shared by all presets.";
25
- readonly peSaveCopy: "Save new preset";
26
- readonly peSaved: "Saved. Select this preset in a new conversation.";
27
- readonly pmGlobalSettings: "Global settings";
28
- readonly pmRefresh: "Refresh";
29
- readonly pmBuiltIn: "Built-in";
30
- readonly pmCustom: "Custom";
31
- readonly pmDiscard: "Discard your unsaved changes?";
32
- readonly pmConflict: "This preset changed in another page or on disk. Reopen the latest version before saving.";
33
- readonly pmYamlError: "The configuration must be valid YAML. Your draft has not been saved.";
34
- readonly pmErrorDetails: "Technical details";
35
- readonly pmSaveError: "Could not complete this action. Your draft is still here.";
36
- readonly pmName: "Name";
37
- readonly pmDescription: "Description";
38
- readonly pmCancel: "Cancel";
39
- readonly pmSave: "Save changes";
40
- };
41
- export declare const presetZh: Record<keyof typeof presetEn, string>;
42
- //# sourceMappingURL=preset-copy.d.ts.map
@@ -1,81 +0,0 @@
1
- export const presetEn = {
2
- peConnectionError: 'Could not connect to the local service. Retry loading; if the connection still fails, reconnect the page.',
3
- peReadError: 'Could not read this preset. Retry loading or refresh the preset list.',
4
- peRetryRead: 'Retry loading',
5
- peReconnect: 'Reconnect page',
6
- peSystemPrompt: 'System prompt sections',
7
- peSectionsHint: 'These templates contribute to this preset’s system prompt before the tools. Runtime variables, workspace instructions and plugin-provided guidance are assembled when the conversation runs.',
8
- peDynamicPrompt: 'This field is an expression; it is preserved without executing it in the editor.',
9
- peDshSourcePrompt: 'Tells the agent where the DSH source checkout is and keeps it separate from the current workspace. It is used when inspecting or extending DSH itself.',
10
- peDshWebPrompt: 'Tells the agent which Web page it is talking through, what “this page” means, and when Web changes need a rebuild or refresh.',
11
- peSuppressed: 'Not used',
12
- peCompletePersona: 'This preset uses Persona as its entire system prompt, so this section is excluded.',
13
- peLoading: 'Reading preset…',
14
- peTitle: 'Preset editor',
15
- peHierarchy: 'Codex mode and other presets are peers. Choose one to edit, or make an editable copy of a built-in preset first.',
16
- peSelect: 'Preset',
17
- peSelectPlaceholder: 'Choose a preset…',
18
- peEditable: 'This is an editable user preset.',
19
- peBuiltinEdit: 'Built-in presets are read-only. Create a copy to edit it.',
20
- peCreateCopy: 'Create editable copy',
21
- peCodexSection: 'Codex mode capabilities',
22
- peAddCodex: 'Add Codex capabilities to this preset',
23
- peAddCodexHint: 'Adds the Codex prompt, tools, hosted search, and remote compaction to this preset.',
24
- peActivityGlobal: 'Activity status is a global display setting and is shared by all presets.',
25
- peSaveCopy: 'Save new preset',
26
- peSaved: 'Saved. Select this preset in a new conversation.',
27
- pmGlobalSettings: 'Global settings',
28
- pmRefresh: 'Refresh',
29
- pmBuiltIn: 'Built-in',
30
- pmCustom: 'Custom',
31
- pmDiscard: 'Discard your unsaved changes?',
32
- pmConflict: 'This preset changed in another page or on disk. Reopen the latest version before saving.',
33
- pmYamlError: 'The configuration must be valid YAML. Your draft has not been saved.',
34
- pmErrorDetails: 'Technical details',
35
- pmSaveError: 'Could not complete this action. Your draft is still here.',
36
- pmName: 'Name',
37
- pmDescription: 'Description',
38
- pmCancel: 'Cancel',
39
- pmSave: 'Save changes',
40
- };
41
- export const presetZh = {
42
- peConnectionError: '未能连接本地服务。请重试读取;如果仍然失败,请重新连接页面。',
43
- peReadError: '无法读取这个预设,请重试读取或刷新预设列表。',
44
- peRetryRead: '重试读取',
45
- peReconnect: '重新连接页面',
46
- peSystemPrompt: '系统提示词',
47
- peSectionsHint: '这些模板共同组成当前预设在工具之前的系统提示词。运行时变量、工作区指令和插件提供的说明会在会话中组装。',
48
- peDynamicPrompt: '此字段是动态表达式,编辑器保留原值,不执行表达式。',
49
- peDshSourcePrompt: '告诉 Agent DSH 源码检出目录在哪里,并与当前工作区区分开;用于检查或扩展 DSH 本身。',
50
- peDshWebPrompt: '告诉 Agent 当前通过哪个 Web 页面交互、“这个页面”指什么,以及 Web 修改何时需要重建或刷新。',
51
- peSuppressed: '未使用',
52
- peCompletePersona: '此预设将 Persona 作为完整系统提示词,因此不使用这一段。',
53
- peLoading: '正在读取预设…',
54
- peTitle: '预设编辑',
55
- peHierarchy: 'Codex 模式和其它预设处于同一级。选择一个预设编辑;内置预设先创建可编辑副本。',
56
- peSelect: '选择预设',
57
- peSelectPlaceholder: '选择一个预设…',
58
- peEditable: '这是可编辑的用户预设。',
59
- peBuiltinEdit: '内置预设只读,需要先创建副本。',
60
- peCreateCopy: '创建可编辑副本',
61
- peCodexSection: 'Codex 模式能力',
62
- peAddCodex: '为这个预设加入 Codex 能力',
63
- peAddCodexHint: '加入 Codex 提示词、工具、托管搜索和远程上下文压缩。',
64
- peActivityGlobal: '活动状态是全局显示设置,由所有预设共享。',
65
- peSaveCopy: '保存新预设',
66
- peSaved: '已保存,在新会话中选择此预设即可使用。',
67
- pmGlobalSettings: '全局设置',
68
- pmRefresh: '刷新',
69
- pmBuiltIn: '内置',
70
- pmCustom: '自定义',
71
- pmDiscard: '放弃尚未保存的修改?',
72
- pmConflict: '此预设已被其他页面或文件修改,请重新打开最新版本后再保存。',
73
- pmYamlError: '配置必须是有效 YAML,草稿尚未保存。',
74
- pmErrorDetails: '技术详情',
75
- pmSaveError: '操作未完成,填写的内容仍然保留。',
76
- pmName: '名称',
77
- pmDescription: '用途说明',
78
- pmCancel: '取消',
79
- pmSave: '保存修改',
80
- };
81
- //# sourceMappingURL=preset-copy.js.map
@@ -1,79 +0,0 @@
1
- /** Codex-aware `/compact` command with an optional transport preference. */
2
- import { ManualCompactionError } from '@deepseek-ai/dsh-compaction';
3
- import { runCodexCompactionMode } from "./compaction.js";
4
- const USAGE = 'Usage: /compact [remote|local]';
5
- /** Convert expected backend failures into the same concise command results as DSH Core. */
6
- function expectedFailure(error) {
7
- switch (error.code) {
8
- case 'busy':
9
- return { kind: 'error', text: 'Compaction is unavailable because this process has an active compaction, or the agent is not idle.' };
10
- case 'cancelled':
11
- return { kind: 'error', text: 'Compaction cancelled.' };
12
- case 'changed':
13
- return { kind: 'error', text: 'Compaction could not replace the selected history because it changed. The conversation is unchanged.' };
14
- case 'summary':
15
- return { kind: 'error', text: 'Compaction could not produce a useful summary. The conversation is unchanged; the attempt is recorded in the session log.' };
16
- case 'commit':
17
- return { kind: 'error', text: 'Compaction did not finish cleanly; inspect the current session state before retrying.' };
18
- case 'persistence':
19
- return { kind: 'error', text: 'Compaction finished, but the session could not be saved.' };
20
- default:
21
- return { kind: 'error', text: `Unknown compaction failure: ${String(error.code)}` };
22
- }
23
- }
24
- function modeOf(rawInput) {
25
- const value = rawInput.trim().toLowerCase();
26
- if (value === '')
27
- return undefined;
28
- if (value === 'remote' || value === 'local')
29
- return value;
30
- return 'invalid';
31
- }
32
- async function executeCompact(ctx, invocation) {
33
- const mode = modeOf(invocation.rawInput);
34
- if (mode === 'invalid')
35
- return { kind: 'error', text: USAGE };
36
- const compact = () => ctx.compaction.compactNow(invocation.agent, invocation.signal, invocation.commandId);
37
- try {
38
- const result = mode === undefined ? await compact() : await runCodexCompactionMode(mode, compact);
39
- if (result === null)
40
- return { kind: 'success', text: 'No compactable history yet.' };
41
- return {
42
- kind: 'success',
43
- text: `Compacted ${result.shadowedSeqs.length} history items (~${result.shadowedTokenCount} tokens).`,
44
- sourceEventSeq: result.summarySeq,
45
- };
46
- }
47
- catch (error) {
48
- if (invocation.signal.aborted)
49
- return { kind: 'error', text: 'Compaction cancelled.' };
50
- if (error instanceof ManualCompactionError)
51
- return expectedFailure(error);
52
- throw error;
53
- }
54
- }
55
- /** Replace the Core command inside the Codex compaction scope. */
56
- export function apply(ctx) {
57
- const commands = ctx.commands;
58
- const active = new Set();
59
- const handler = (invocation) => {
60
- const operation = executeCompact(ctx, invocation);
61
- active.add(operation);
62
- const retire = () => { active.delete(operation); };
63
- operation.then(retire, retire);
64
- return operation;
65
- };
66
- ctx.effect(function* () {
67
- yield async () => { await Promise.allSettled(active); };
68
- yield commands.register({
69
- name: 'compact',
70
- description: 'Compact older conversation history, optionally using remote or local mode',
71
- input: { hint: '[remote|local]' },
72
- handler,
73
- });
74
- }, 'codex compact command lifecycle');
75
- }
76
- export const name = 'compact-command';
77
- export const inject = ['commands', 'compaction'];
78
- export default { name, inject, apply };
79
- //# sourceMappingURL=compact-command.js.map
@@ -1,8 +0,0 @@
1
- /** User-selectable Codex context controls use whole K-token units. */
2
- export declare const CODEX_CONTEXT_UNIT = 1000;
3
- export declare const CODEX_CONTEXT_MAX = 1000000;
4
- export declare const CODEX_PRESET_ID = "codex";
5
- export declare const CODEX_COLLABORATION_PRESET_ID = "codex-collaboration";
6
- /** The bundled preset and legacy Codex sessions share the same Web controls. */
7
- export declare function isCodexPresetId(value: string | undefined): boolean;
8
- //# sourceMappingURL=context.d.ts.map
@@ -1,14 +0,0 @@
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
- const CODEX_PRESET_IDS = new Set([
7
- CODEX_PRESET_ID,
8
- CODEX_COLLABORATION_PRESET_ID,
9
- ]);
10
- /** The bundled preset and legacy Codex sessions share the same Web controls. */
11
- export function isCodexPresetId(value) {
12
- return value !== undefined && CODEX_PRESET_IDS.has(value);
13
- }
14
- //# sourceMappingURL=context.js.map
@@ -1,46 +0,0 @@
1
- /** Codex `exec_command` and `write_stdin` execution over dsh capability seams. */
2
- import type { Context } from '@deepseek-ai/cordis';
3
- import type { ToolExecution } from '@deepseek-ai/dsh-tools';
4
- /** The exact model-facing argument vocabulary of Codex's unified exec tool. */
5
- export interface ExecCommandArgs {
6
- cmd: string;
7
- workdir?: string;
8
- tty?: boolean;
9
- run_in_background?: boolean;
10
- yield_time_ms?: number;
11
- max_output_tokens?: number;
12
- shell?: string;
13
- login?: boolean;
14
- }
15
- /** The exact model-facing argument vocabulary of Codex's stdin poll tool. */
16
- export interface WriteStdinArgs {
17
- session_id: number;
18
- chars?: string;
19
- yield_time_ms?: number;
20
- max_output_tokens?: number;
21
- }
22
- /** Canonical result fields shared by both unified exec tools. */
23
- export interface ExecResult {
24
- chunk_id?: string;
25
- wall_time_seconds: number;
26
- output: string;
27
- session_id?: number;
28
- job_id?: string;
29
- exit_code?: number;
30
- original_token_count?: number;
31
- }
32
- export declare function normalizeWaitMs(value: number | undefined, fallback: number, empty?: boolean, initialExec?: boolean): number;
33
- /** Render the ordinary Responses tool result text used by Codex's unified exec tools. */
34
- export declare function renderExecResult(result: ExecResult): string;
35
- /** Execute one Codex command through the configured pipe or PTY capability. */
36
- export declare function runExecCommand(ctx: Context, args: ExecCommandArgs, exec: ToolExecution, config: {
37
- defaultYieldTimeMs: number;
38
- maxOutputBytes: number;
39
- }): Promise<ExecResult>;
40
- /** Poll or write to one session returned by {@link runExecCommand}. */
41
- export declare function runWriteStdin(ctx: Context, args: WriteStdinArgs, exec: ToolExecution, config: {
42
- pollYieldTimeMs: number;
43
- writeYieldTimeMs: number;
44
- maxOutputBytes: number;
45
- }): Promise<ExecResult>;
46
- //# sourceMappingURL=exec.d.ts.map