@shuind/dsh-codex-harness 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +21 -41
  3. package/docs/preset-library.md +2 -2
  4. package/docs/tool-policy.md +1 -1
  5. package/lib/client.js +1826 -545
  6. package/lib/compact-command.js +7 -1
  7. package/lib/compaction.js +7 -1
  8. package/lib/hybrid-executor.js +23 -12
  9. package/lib/index.js +1229 -17
  10. package/lib/preferences.js +21 -2
  11. package/lib/tool-policy.js +11 -2
  12. package/lib/typert.js +42 -1
  13. package/lib/types/client/desktop.d.ts +20 -42
  14. package/lib/types/client/desktop.js +184 -127
  15. package/lib/types/client/index.d.ts +104 -39
  16. package/lib/types/client/index.js +97 -15
  17. package/lib/types/client/policy-drafts.d.ts +18 -0
  18. package/lib/types/client/policy-drafts.js +27 -0
  19. package/lib/types/client/policy-locale.d.ts +81 -32
  20. package/lib/types/client/policy-locale.js +197 -107
  21. package/lib/types/client/preset-manager.d.ts +25 -2
  22. package/lib/types/client/preset-manager.js +89 -5
  23. package/lib/types/client/preset-requests.d.ts +44 -1
  24. package/lib/types/client/preset-requests.js +150 -0
  25. package/lib/types/client/tool-policy.d.ts +6 -15
  26. package/lib/types/client/tool-policy.js +24 -39
  27. package/lib/types/contracts/preset-editor-schema.d.ts +35 -0
  28. package/lib/types/contracts/preset-editor-schema.js +39 -0
  29. package/lib/types/contracts/settings.d.ts +12 -0
  30. package/lib/types/contracts/settings.js +10 -1
  31. package/lib/types/contracts/ui-contracts.d.ts +48 -0
  32. package/lib/types/contracts/ui-contracts.js +58 -0
  33. package/lib/types/contracts/update.d.ts +73 -0
  34. package/lib/types/contracts/update.js +291 -0
  35. package/lib/types/entries/index.js +20 -2
  36. package/lib/types/entries/preferences.d.ts +2 -0
  37. package/lib/types/entries/preferences.js +9 -0
  38. package/lib/types/hybrid/hybrid-sdk.d.ts +1 -1
  39. package/lib/types/hybrid/hybrid-sdk.js +27 -13
  40. package/lib/types/presets/preset-editor.d.ts +13 -1
  41. package/lib/types/presets/preset-editor.js +24 -1
  42. package/lib/types/presets/pro-mode-store.d.ts +13 -0
  43. package/lib/types/presets/pro-mode-store.js +69 -0
  44. package/lib/types/responses/background-sse-codec.d.ts +23 -0
  45. package/lib/types/responses/background-sse-codec.js +230 -0
  46. package/lib/types/responses/background-stream.d.ts +28 -0
  47. package/lib/types/responses/background-stream.js +351 -0
  48. package/lib/types/responses/fetch-transport.js +24 -9
  49. package/lib/types/responses/wire-rewrite.d.ts +4 -0
  50. package/lib/types/responses/wire-rewrite.js +30 -4
  51. package/lib/types/tools/codex-subagent.d.ts +14 -0
  52. package/lib/types/tools/codex-subagent.js +269 -0
  53. package/lib/types/update/checker.d.ts +14 -0
  54. package/lib/types/update/checker.js +166 -0
  55. package/locale/en.json +1 -1
  56. package/locale/hybrid-executor/en.json +1 -1
  57. package/locale/hybrid-executor/zh.json +1 -1
  58. package/locale/zh.json +1 -1
  59. package/package.json +6 -2
  60. package/src/client/desktop.tsx +359 -160
  61. package/src/client/index.tsx +122 -22
  62. package/src/client/policy-drafts.ts +45 -0
  63. package/src/client/policy-locale.ts +198 -106
  64. package/src/client/preset-manager.tsx +125 -4
  65. package/src/client/preset-requests.ts +185 -1
  66. package/src/client/tool-policy.tsx +29 -63
  67. package/src/contracts/preset-editor-schema.ts +44 -0
  68. package/src/contracts/settings.ts +20 -1
  69. package/src/contracts/ui-contracts.ts +87 -0
  70. package/src/contracts/update.ts +307 -0
  71. package/src/entries/index.ts +25 -2
  72. package/src/entries/preferences.ts +9 -0
  73. package/src/hybrid/hybrid-sdk.ts +28 -12
  74. package/src/presets/preset-editor.ts +31 -3
  75. package/src/presets/pro-mode-store.ts +80 -0
  76. package/src/responses/background-sse-codec.ts +237 -0
  77. package/src/responses/background-stream.ts +371 -0
  78. package/src/responses/fetch-transport.ts +28 -9
  79. package/src/responses/wire-rewrite.ts +34 -3
  80. package/src/tools/codex-subagent.ts +290 -0
  81. package/src/update/checker.ts +193 -0
  82. package/tsdown.config.ts +4 -0
@@ -6,6 +6,52 @@ export declare const CODEX_CONTEXT_MAX = 1000000;
6
6
  export declare const OPENAI_CODEX_PROVIDER = "openai-codex";
7
7
  export declare const OPENAI_CODEX_SETTINGS_NAMESPACE = "llm-openai-codex";
8
8
  export declare const OPENAI_CODEX_MODEL_CATALOG_PATH = "/plugins/dsh-codex-connect/models";
9
+ export declare const CODEX_SUBAGENT_TOOL_NAME = "codex_subagent";
10
+ export declare const CODEX_SUBAGENT_DEFAULT_PRESET = "codex-hybrid";
11
+ export declare const CODEX_SUBAGENT_PRESET_INHERIT = "inherit";
12
+ export interface CodexSubagentModelOption {
13
+ readonly id: string;
14
+ readonly name: string;
15
+ readonly efforts: readonly string[];
16
+ readonly defaultEffort?: string;
17
+ }
18
+ export interface CodexSubagentModelCatalog {
19
+ readonly available: boolean;
20
+ readonly models: readonly CodexSubagentModelOption[];
21
+ }
22
+ /**
23
+ * Models on the OpenAI Responses API that accept `reasoning.mode = "pro"`.
24
+ * Excludes standalone legacy `*-pro` slugs (e.g. `gpt-5.4-pro`, `gpt-5.5-pro`).
25
+ */
26
+ export declare function supportsApiProMode(model: unknown): model is string;
27
+ export interface LlmProviderRouteProfile {
28
+ readonly api?: string | undefined;
29
+ readonly baseURL?: string | undefined;
30
+ readonly baseUrl?: string | undefined;
31
+ readonly models?: readonly {
32
+ readonly id?: string;
33
+ readonly api?: string;
34
+ readonly baseURL?: string;
35
+ readonly baseUrl?: string;
36
+ }[] | undefined;
37
+ readonly modelOverrides?: Readonly<Record<string, {
38
+ readonly api?: string;
39
+ readonly baseURL?: string;
40
+ readonly baseUrl?: string;
41
+ }>> | undefined;
42
+ }
43
+ export type LlmProvidersMap = Readonly<Record<string, LlmProviderRouteProfile>>;
44
+ export interface LlmProvidersScope {
45
+ getSnapshot(): LlmProvidersMap | undefined;
46
+ subscribe(listener: () => void): () => void;
47
+ }
48
+ /** True only when `url` is an HTTPS official OpenAI API endpoint (`api.openai.com`). */
49
+ export declare function isOfficialOpenAiBaseUrl(url: unknown): boolean;
50
+ /**
51
+ * True only when `(provider, model)` routes to the official OpenAI Responses API
52
+ * (`https://api.openai.com`) on a Pro-capable GPT-5.6 / 6+ model.
53
+ */
54
+ export declare function isOfficialOpenAiApiRoute(provider: string | undefined, model: string | undefined, providers?: LlmProvidersMap | undefined): boolean;
9
55
  export interface ContextWindowBounds {
10
56
  readonly defaultTokens?: number;
11
57
  readonly maxTokens: number;
@@ -88,6 +134,8 @@ export interface CodexConnectScope {
88
134
  subscribe(listener: () => void): () => void;
89
135
  setModelOverride(modelId: string, tokens: number | undefined): Promise<void>;
90
136
  setNativeCompaction?(enabled: boolean): Promise<void>;
137
+ setSearchEnabled?(enabled: boolean): Promise<void>;
138
+ setImageGenerationEnabled?(enabled: boolean): Promise<void>;
91
139
  }
92
140
  export interface PresetPromptCatalog {
93
141
  readonly preset: string;
@@ -6,6 +6,64 @@ export const CODEX_CONTEXT_MAX = 1_000_000;
6
6
  export const OPENAI_CODEX_PROVIDER = 'openai-codex';
7
7
  export const OPENAI_CODEX_SETTINGS_NAMESPACE = 'llm-openai-codex';
8
8
  export const OPENAI_CODEX_MODEL_CATALOG_PATH = '/plugins/dsh-codex-connect/models';
9
+ export const CODEX_SUBAGENT_TOOL_NAME = 'codex_subagent';
10
+ export const CODEX_SUBAGENT_DEFAULT_PRESET = 'codex-hybrid';
11
+ export const CODEX_SUBAGENT_PRESET_INHERIT = 'inherit';
12
+ const API_PRO_MODE_MODEL = /^gpt-(?:5\.6|[6-9]|\d{2,})(?:[._-]|$)/i;
13
+ const LEGACY_PRO_MODEL_SLUG = /(?:^|[-_.])pro(?:$|[-_.])/i;
14
+ /**
15
+ * Models on the OpenAI Responses API that accept `reasoning.mode = "pro"`.
16
+ * Excludes standalone legacy `*-pro` slugs (e.g. `gpt-5.4-pro`, `gpt-5.5-pro`).
17
+ */
18
+ export function supportsApiProMode(model) {
19
+ if (typeof model !== 'string')
20
+ return false;
21
+ const trimmed = model.trim();
22
+ if (trimmed.length === 0)
23
+ return false;
24
+ const base = trimmed.includes('/') ? trimmed.slice(trimmed.lastIndexOf('/') + 1) : trimmed;
25
+ return API_PRO_MODE_MODEL.test(base) && !LEGACY_PRO_MODEL_SLUG.test(base);
26
+ }
27
+ /** True only when `url` is an HTTPS official OpenAI API endpoint (`api.openai.com`). */
28
+ export function isOfficialOpenAiBaseUrl(url) {
29
+ if (typeof url !== 'string')
30
+ return false;
31
+ const trimmed = url.trim();
32
+ if (trimmed.length === 0)
33
+ return false;
34
+ try {
35
+ const parsed = new URL(trimmed);
36
+ return parsed.protocol === 'https:' && parsed.hostname.toLowerCase() === 'api.openai.com';
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ }
42
+ /**
43
+ * True only when `(provider, model)` routes to the official OpenAI Responses API
44
+ * (`https://api.openai.com`) on a Pro-capable GPT-5.6 / 6+ model.
45
+ */
46
+ export function isOfficialOpenAiApiRoute(provider, model, providers) {
47
+ if (typeof provider !== 'string' || provider.length === 0 || provider === OPENAI_CODEX_PROVIDER)
48
+ return false;
49
+ if (!supportsApiProMode(model))
50
+ return false;
51
+ const profile = providers?.[provider];
52
+ const override = model !== undefined ? profile?.modelOverrides?.[model] : undefined;
53
+ const modelEntry = model !== undefined && Array.isArray(profile?.models)
54
+ ? profile.models.find(item => item?.id === model)
55
+ : undefined;
56
+ const effectiveApi = override?.api ?? modelEntry?.api ?? profile?.api;
57
+ if (effectiveApi !== undefined && effectiveApi !== 'openai-responses')
58
+ return false;
59
+ const effectiveBaseUrl = override?.baseURL ?? override?.baseUrl
60
+ ?? modelEntry?.baseURL ?? modelEntry?.baseUrl
61
+ ?? profile?.baseURL ?? profile?.baseUrl;
62
+ if (typeof effectiveBaseUrl === 'string' && effectiveBaseUrl.trim().length > 0) {
63
+ return isOfficialOpenAiBaseUrl(effectiveBaseUrl);
64
+ }
65
+ return provider === 'openai';
66
+ }
9
67
  export const OPENAI_CODEX_MODEL_LIMITS = {
10
68
  'gpt-6.1-sol': { defaultTokens: 500_000, maxTokens: 872_000 },
11
69
  'gpt-6.1-terra': { defaultTokens: 500_000, maxTokens: 872_000 },
@@ -0,0 +1,73 @@
1
+ /** Node-free update constants, SemVer helpers, and browser update store for Codex Harness. */
2
+ export declare const CODEX_HARNESS_PACKAGE_NAME = "@shuind/dsh-codex-harness";
3
+ export declare const CODEX_HARNESS_REPO_URL = "https://github.com/shuind/dsh-codex-harness";
4
+ export declare const CODEX_HARNESS_RELEASES_URL = "https://github.com/shuind/dsh-codex-harness/releases";
5
+ export declare const CODEX_HARNESS_RELEASE_TAG_BASE = "https://github.com/shuind/dsh-codex-harness/releases/tag/v";
6
+ export declare const CODEX_HARNESS_NPM_METADATA_URL = "https://registry.npmjs.org/-/package/@shuind/dsh-codex-harness/dist-tags";
7
+ export declare const CODEX_HARNESS_GITHUB_LATEST_RELEASE_URL = "https://api.github.com/repos/shuind/dsh-codex-harness/releases/latest";
8
+ export declare const CODEX_CONNECT_PACKAGE_NAME = "@shuind/dsh-codex-connect";
9
+ export declare const CODEX_CONNECT_REPO_URL = "https://github.com/shuind/dsh-codex-connect";
10
+ export declare const CODEX_HARNESS_UPDATE_CACHE_KEY = "@shuind/dsh-codex-harness:update-check";
11
+ export declare const CODEX_HARNESS_UPDATE_DISMISSED_KEY = "@shuind/dsh-codex-harness:update-seen";
12
+ export declare const CODEX_HARNESS_UPDATE_CACHE_TTL_MS: number;
13
+ export declare const CODEX_HARNESS_UPDATE_RECHECK_MS: number;
14
+ export type HarnessUpdateResult = {
15
+ status: 'up-to-date';
16
+ currentVersion: string;
17
+ latestVersion: string;
18
+ } | {
19
+ status: 'update-available';
20
+ currentVersion: string;
21
+ latestVersion: string;
22
+ releaseUrl: string;
23
+ } | {
24
+ status: 'unavailable';
25
+ currentVersion: string;
26
+ reason: 'invalid-current-version' | 'registry-unavailable' | 'invalid-registry-response';
27
+ };
28
+ export interface HarnessUpdateSnapshot {
29
+ readonly status: 'idle' | 'checking' | HarnessUpdateResult['status'];
30
+ readonly currentVersion?: string;
31
+ readonly checkedAt?: number;
32
+ readonly latestVersion?: string;
33
+ readonly releaseUrl?: string;
34
+ readonly dismissedNotice?: string;
35
+ }
36
+ interface ParsedVersion {
37
+ major: number;
38
+ minor: number;
39
+ patch: number;
40
+ prerelease: Array<number | string>;
41
+ }
42
+ export declare function normalizeHarnessVersion(raw: string): string;
43
+ export declare function harnessReleaseUrl(version: string): string;
44
+ export declare function parseHarnessVersion(raw: string): ParsedVersion | undefined;
45
+ export declare function compareHarnessVersions(left: string, right: string): number;
46
+ export declare function parseHarnessUpdateResult(value: unknown): HarnessUpdateResult | undefined;
47
+ export declare function bundledHarnessVersion(): string | undefined;
48
+ export declare function harnessUpdateNoticeKey(snapshot: HarnessUpdateSnapshot): string | undefined;
49
+ export declare class HarnessUpdateStore {
50
+ private readonly fetchUpdate;
51
+ private readonly initialVersion;
52
+ private snapshot;
53
+ private readonly listeners;
54
+ private readonly shownInSession;
55
+ private dismissedInSession;
56
+ private inFlight;
57
+ private disposed;
58
+ private recheckTimer;
59
+ constructor(fetchUpdate: () => Promise<HarnessUpdateResult | undefined>, initialVersion?: string | undefined);
60
+ getSnapshot: () => HarnessUpdateSnapshot;
61
+ subscribe: (listener: () => void) => (() => void);
62
+ private setSnapshot;
63
+ private effectiveDismissed;
64
+ private readCached;
65
+ private writeCached;
66
+ private toSnapshot;
67
+ refresh(force?: boolean): Promise<void>;
68
+ markShown(notice: string): void;
69
+ dismiss(notice: string): void;
70
+ dispose(): void;
71
+ }
72
+ export {};
73
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1,291 @@
1
+ /** Node-free update constants, SemVer helpers, and browser update store for Codex Harness. */
2
+ export const CODEX_HARNESS_PACKAGE_NAME = '@shuind/dsh-codex-harness';
3
+ export const CODEX_HARNESS_REPO_URL = 'https://github.com/shuind/dsh-codex-harness';
4
+ export const CODEX_HARNESS_RELEASES_URL = 'https://github.com/shuind/dsh-codex-harness/releases';
5
+ export const CODEX_HARNESS_RELEASE_TAG_BASE = 'https://github.com/shuind/dsh-codex-harness/releases/tag/v';
6
+ export const CODEX_HARNESS_NPM_METADATA_URL = `https://registry.npmjs.org/-/package/${CODEX_HARNESS_PACKAGE_NAME}/dist-tags`;
7
+ export const CODEX_HARNESS_GITHUB_LATEST_RELEASE_URL = 'https://api.github.com/repos/shuind/dsh-codex-harness/releases/latest';
8
+ export const CODEX_CONNECT_PACKAGE_NAME = '@shuind/dsh-codex-connect';
9
+ export const CODEX_CONNECT_REPO_URL = 'https://github.com/shuind/dsh-codex-connect';
10
+ export const CODEX_HARNESS_UPDATE_CACHE_KEY = '@shuind/dsh-codex-harness:update-check';
11
+ export const CODEX_HARNESS_UPDATE_DISMISSED_KEY = '@shuind/dsh-codex-harness:update-seen';
12
+ export const CODEX_HARNESS_UPDATE_CACHE_TTL_MS = 24 * 60 * 60 * 1_000;
13
+ export const CODEX_HARNESS_UPDATE_RECHECK_MS = 5 * 60 * 1_000;
14
+ export function normalizeHarnessVersion(raw) {
15
+ return raw.startsWith('v') ? raw.slice(1) : raw;
16
+ }
17
+ export function harnessReleaseUrl(version) {
18
+ return `${CODEX_HARNESS_RELEASE_TAG_BASE}${normalizeHarnessVersion(version)}`;
19
+ }
20
+ export function parseHarnessVersion(raw) {
21
+ if (typeof raw !== 'string')
22
+ return undefined;
23
+ const normalized = normalizeHarnessVersion(raw.trim());
24
+ const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u.exec(normalized);
25
+ if (match === null)
26
+ return undefined;
27
+ const rawPrerelease = match[4] === undefined ? [] : match[4].split('.');
28
+ if (rawPrerelease.some(part => /^\d+$/u.test(part) && !/^(0|[1-9]\d*)$/u.test(part)))
29
+ return undefined;
30
+ const prerelease = rawPrerelease.map(part => /^(0|[1-9]\d*)$/u.test(part) ? Number(part) : part);
31
+ if (prerelease.some(part => typeof part === 'number' && !Number.isSafeInteger(part)))
32
+ return undefined;
33
+ const parsed = { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), prerelease };
34
+ return [parsed.major, parsed.minor, parsed.patch].every(Number.isSafeInteger) ? parsed : undefined;
35
+ }
36
+ function compareIdentifiers(left, right) {
37
+ if (typeof left === 'number' && typeof right === 'number')
38
+ return left < right ? -1 : left > right ? 1 : 0;
39
+ if (typeof left === 'number')
40
+ return -1;
41
+ if (typeof right === 'number')
42
+ return 1;
43
+ return left < right ? -1 : left > right ? 1 : 0;
44
+ }
45
+ export function compareHarnessVersions(left, right) {
46
+ const a = parseHarnessVersion(left);
47
+ const b = parseHarnessVersion(right);
48
+ if (a === undefined || b === undefined)
49
+ throw new TypeError('invalid Codex Harness version');
50
+ for (const [aPart, bPart] of [[a.major, b.major], [a.minor, b.minor], [a.patch, b.patch]]) {
51
+ if (aPart !== bPart)
52
+ return aPart < bPart ? -1 : 1;
53
+ }
54
+ if (a.prerelease.length === 0 && b.prerelease.length !== 0)
55
+ return 1;
56
+ if (a.prerelease.length !== 0 && b.prerelease.length === 0)
57
+ return -1;
58
+ for (let i = 0; i < Math.max(a.prerelease.length, b.prerelease.length); i += 1) {
59
+ const aPart = a.prerelease[i];
60
+ const bPart = b.prerelease[i];
61
+ if (aPart === undefined)
62
+ return -1;
63
+ if (bPart === undefined)
64
+ return 1;
65
+ const cmp = compareIdentifiers(aPart, bPart);
66
+ if (cmp !== 0)
67
+ return cmp;
68
+ }
69
+ return 0;
70
+ }
71
+ export function parseHarnessUpdateResult(value) {
72
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
73
+ return undefined;
74
+ const record = value;
75
+ const currentVersion = record['currentVersion'];
76
+ if (typeof currentVersion !== 'string' || parseHarnessVersion(currentVersion) === undefined)
77
+ return undefined;
78
+ if (record['status'] === 'unavailable') {
79
+ const reason = record['reason'];
80
+ return reason === 'invalid-current-version' || reason === 'registry-unavailable' || reason === 'invalid-registry-response'
81
+ ? { status: 'unavailable', currentVersion: normalizeHarnessVersion(currentVersion), reason }
82
+ : undefined;
83
+ }
84
+ const latestVersion = record['latestVersion'];
85
+ if (typeof latestVersion !== 'string' || parseHarnessVersion(latestVersion) === undefined)
86
+ return undefined;
87
+ const normalizedCurrent = normalizeHarnessVersion(currentVersion);
88
+ const normalizedLatest = normalizeHarnessVersion(latestVersion);
89
+ if (record['status'] === 'up-to-date') {
90
+ return { status: 'up-to-date', currentVersion: normalizedCurrent, latestVersion: normalizedLatest };
91
+ }
92
+ if (record['status'] !== 'update-available' || compareHarnessVersions(normalizedLatest, normalizedCurrent) <= 0)
93
+ return undefined;
94
+ const expectedUrl = harnessReleaseUrl(normalizedLatest);
95
+ if (record['releaseUrl'] !== expectedUrl)
96
+ return undefined;
97
+ return { status: 'update-available', currentVersion: normalizedCurrent, latestVersion: normalizedLatest, releaseUrl: expectedUrl };
98
+ }
99
+ export function bundledHarnessVersion() {
100
+ try {
101
+ return typeof __CODEX_HARNESS_VERSION__ === 'string' && parseHarnessVersion(__CODEX_HARNESS_VERSION__) !== undefined
102
+ ? normalizeHarnessVersion(__CODEX_HARNESS_VERSION__)
103
+ : undefined;
104
+ }
105
+ catch {
106
+ return undefined;
107
+ }
108
+ }
109
+ export function harnessUpdateNoticeKey(snapshot) {
110
+ if (snapshot.status !== 'update-available' || !snapshot.currentVersion || !snapshot.latestVersion)
111
+ return undefined;
112
+ return `${snapshot.currentVersion}:${snapshot.latestVersion}`;
113
+ }
114
+ function browserStorage() {
115
+ try {
116
+ return typeof localStorage === 'undefined' ? undefined : localStorage;
117
+ }
118
+ catch {
119
+ return undefined;
120
+ }
121
+ }
122
+ export class HarnessUpdateStore {
123
+ fetchUpdate;
124
+ initialVersion;
125
+ snapshot;
126
+ listeners = new Set();
127
+ shownInSession = new Set();
128
+ dismissedInSession;
129
+ inFlight = false;
130
+ disposed = false;
131
+ recheckTimer;
132
+ constructor(fetchUpdate, initialVersion = bundledHarnessVersion()) {
133
+ this.fetchUpdate = fetchUpdate;
134
+ this.initialVersion = initialVersion;
135
+ this.snapshot = {
136
+ status: 'idle',
137
+ ...(initialVersion === undefined ? {} : { currentVersion: initialVersion }),
138
+ };
139
+ }
140
+ getSnapshot = () => this.snapshot;
141
+ subscribe = (listener) => {
142
+ this.listeners.add(listener);
143
+ return () => { this.listeners.delete(listener); };
144
+ };
145
+ setSnapshot(next) {
146
+ if (this.disposed)
147
+ return;
148
+ this.snapshot = next;
149
+ for (const listener of [...this.listeners])
150
+ listener();
151
+ }
152
+ effectiveDismissed() {
153
+ if (this.dismissedInSession !== undefined)
154
+ return this.dismissedInSession;
155
+ try {
156
+ const stored = browserStorage()?.getItem(CODEX_HARNESS_UPDATE_DISMISSED_KEY);
157
+ if (!stored)
158
+ return undefined;
159
+ return this.shownInSession.has(stored) ? undefined : stored;
160
+ }
161
+ catch {
162
+ return undefined;
163
+ }
164
+ }
165
+ readCached() {
166
+ try {
167
+ const raw = browserStorage()?.getItem(CODEX_HARNESS_UPDATE_CACHE_KEY);
168
+ if (!raw)
169
+ return undefined;
170
+ const parsed = JSON.parse(raw);
171
+ if (typeof parsed.checkedAt !== 'number' || !Number.isSafeInteger(parsed.checkedAt))
172
+ return undefined;
173
+ const now = Date.now();
174
+ if (parsed.checkedAt > now || now - parsed.checkedAt > CODEX_HARNESS_UPDATE_CACHE_TTL_MS)
175
+ return undefined;
176
+ const result = parseHarnessUpdateResult(parsed.result);
177
+ if (result === undefined || result.status === 'unavailable')
178
+ return undefined;
179
+ if (this.initialVersion !== undefined && result.currentVersion !== this.initialVersion)
180
+ return undefined;
181
+ return { result, checkedAt: parsed.checkedAt };
182
+ }
183
+ catch {
184
+ return undefined;
185
+ }
186
+ }
187
+ writeCached(result, checkedAt) {
188
+ try {
189
+ if (result.status === 'unavailable')
190
+ browserStorage()?.removeItem(CODEX_HARNESS_UPDATE_CACHE_KEY);
191
+ else
192
+ browserStorage()?.setItem(CODEX_HARNESS_UPDATE_CACHE_KEY, JSON.stringify({ checkedAt, result }));
193
+ }
194
+ catch {
195
+ // Ignore blocked browser storage.
196
+ }
197
+ }
198
+ toSnapshot(result, checkedAt) {
199
+ const dismissedNotice = this.effectiveDismissed();
200
+ return {
201
+ status: result.status,
202
+ currentVersion: result.currentVersion,
203
+ checkedAt,
204
+ ...(result.status === 'up-to-date' || result.status === 'update-available' ? { latestVersion: result.latestVersion } : {}),
205
+ ...(result.status === 'update-available' ? { releaseUrl: result.releaseUrl } : {}),
206
+ ...(dismissedNotice === undefined ? {} : { dismissedNotice }),
207
+ };
208
+ }
209
+ async refresh(force = false) {
210
+ if (this.disposed || this.inFlight)
211
+ return;
212
+ clearTimeout(this.recheckTimer);
213
+ this.recheckTimer = undefined;
214
+ this.inFlight = true;
215
+ const dismissedNotice = this.effectiveDismissed();
216
+ this.setSnapshot({
217
+ status: 'checking',
218
+ ...(this.snapshot.currentVersion === undefined ? {} : { currentVersion: this.snapshot.currentVersion }),
219
+ ...(dismissedNotice === undefined ? {} : { dismissedNotice }),
220
+ });
221
+ try {
222
+ if (!force) {
223
+ const cached = this.readCached();
224
+ if (cached !== undefined) {
225
+ this.setSnapshot(this.toSnapshot(cached.result, cached.checkedAt));
226
+ return;
227
+ }
228
+ }
229
+ const raw = await this.fetchUpdate();
230
+ if (this.disposed)
231
+ return;
232
+ const valid = parseHarnessUpdateResult(raw);
233
+ if (valid !== undefined) {
234
+ const checkedAt = Date.now();
235
+ this.writeCached(valid, checkedAt);
236
+ this.setSnapshot(this.toSnapshot(valid, checkedAt));
237
+ if (valid.status === 'unavailable') {
238
+ this.recheckTimer = setTimeout(() => { void this.refresh(true); }, CODEX_HARNESS_UPDATE_RECHECK_MS);
239
+ }
240
+ return;
241
+ }
242
+ const fallbackVersion = this.snapshot.currentVersion ?? this.initialVersion;
243
+ this.setSnapshot({
244
+ status: 'unavailable',
245
+ ...(fallbackVersion === undefined ? {} : { currentVersion: fallbackVersion }),
246
+ checkedAt: Date.now(),
247
+ ...(dismissedNotice === undefined ? {} : { dismissedNotice }),
248
+ });
249
+ }
250
+ catch {
251
+ if (this.disposed)
252
+ return;
253
+ const fallbackVersion = this.snapshot.currentVersion ?? this.initialVersion;
254
+ this.setSnapshot({
255
+ status: 'unavailable',
256
+ ...(fallbackVersion === undefined ? {} : { currentVersion: fallbackVersion }),
257
+ checkedAt: Date.now(),
258
+ ...(dismissedNotice === undefined ? {} : { dismissedNotice }),
259
+ });
260
+ }
261
+ finally {
262
+ this.inFlight = false;
263
+ }
264
+ }
265
+ markShown(notice) {
266
+ this.shownInSession.add(notice);
267
+ try {
268
+ browserStorage()?.setItem(CODEX_HARNESS_UPDATE_DISMISSED_KEY, notice);
269
+ }
270
+ catch {
271
+ // Fall back to in-session tracking.
272
+ }
273
+ }
274
+ dismiss(notice) {
275
+ this.dismissedInSession = notice;
276
+ try {
277
+ browserStorage()?.setItem(CODEX_HARNESS_UPDATE_DISMISSED_KEY, notice);
278
+ }
279
+ catch {
280
+ // Keep in-session dismissal.
281
+ }
282
+ this.setSnapshot({ ...this.snapshot, dismissedNotice: notice });
283
+ }
284
+ dispose() {
285
+ this.disposed = true;
286
+ clearTimeout(this.recheckTimer);
287
+ this.recheckTimer = undefined;
288
+ this.listeners.clear();
289
+ }
290
+ }
291
+ //# sourceMappingURL=update.js.map
@@ -2,9 +2,10 @@
2
2
  import z from '@deepseek-ai/schemastery';
3
3
  import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, resolveCodexSystemPrompt, } from "../contracts/prompt.js";
4
4
  import { CODEX_SETTINGS_ENTRY, CODEX_SETTINGS_NAMESPACE, isGptModel, readHostSettings, } from "../contracts/settings.js";
5
- import { CODEX_CONTEXT_MAX, OPENAI_CODEX_MODEL_LIMITS } from "../contracts/ui-contracts.js";
5
+ import { CODEX_CONTEXT_MAX, isOfficialOpenAiApiRoute, OPENAI_CODEX_MODEL_LIMITS, } from "../contracts/ui-contracts.js";
6
6
  import { hasPresetPromptOverride } from "../policy/tool-capabilities.js";
7
7
  import { registerCodexActivityProjection } from "../presets/activity.js";
8
+ import { proModeStoreFor } from "../presets/pro-mode-store.js";
8
9
  import { applyCodexPresentationSettings, applyCodexRequestSettings, buildCodexSystemPrompt, enrichCodexModel, installCodexContextProjection, installPresetEditor, normalizeCodexPromptAssembly, syncCodexContextWindow, watchConfiguredGptModels, withPresetPrompt, } from "../presets/runtime-enhancements.js";
9
10
  import { installSmallWindowCompaction } from "../presets/small-window-compaction.js";
10
11
  import { collectTrustedCompactionMarkers } from "../responses/compact-checkpoint.js";
@@ -13,6 +14,7 @@ import { hasDirectResponsesCompactRoute, remoteCompactStream } from "../response
13
14
  import { repairLegacyPiAiContextOverflow } from "../responses/sse-diagnostics.js";
14
15
  import { DEFAULT_MAX_OUTPUT_BYTES, registerCodexExecAndPlan, registerExecTools, registerPlanTool, } from "../tools/exec-plan-tools.js";
15
16
  import { registerPatchTool } from "../tools/patch-tool.js";
17
+ import { installCodexSubagent } from "../tools/codex-subagent.js";
16
18
  import { installGlobalCompactCommand } from "./compact-command.js";
17
19
  import { codexCompactionMode, withExplicitLocalCompactionInstruction } from "./compaction.js";
18
20
  export { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, };
@@ -99,6 +101,7 @@ export function apply(ctx, config = {}) {
99
101
  // Native presets reject host services in their isolated composition.
100
102
  installPresetEditor(ctx);
101
103
  installGlobalCompactCommand(ctx);
104
+ installCodexSubagent(ctx, codexSettings.current);
102
105
  // The generic pi-ai plugin remains the owner of provider routes. This
103
106
  // layer adds only request metadata and remote-first transport behavior.
104
107
  watchConfiguredGptModels(ctx);
@@ -114,13 +117,27 @@ export function apply(ctx, config = {}) {
114
117
  lastRequestByAgent.set(agent, updated);
115
118
  return updated;
116
119
  });
120
+ const proModeStore = proModeStoreFor(ctx);
117
121
  if (typeof ctx.effect === 'function') {
118
122
  const disposeHostedWebSearch = installHostedWebSearch();
119
- ctx.effect(() => disposeHostedWebSearch, 'codex: Responses transport wrapper');
123
+ ctx.effect(() => () => {
124
+ disposeHostedWebSearch();
125
+ proModeStore.clear();
126
+ }, 'codex: Responses transport wrapper');
120
127
  }
121
128
  ctx.on('llm/stream', ((options, next) => {
122
129
  const settings = codexSettings.current();
123
130
  const isCodexConnect = options.provider === 'openai-codex';
131
+ const sessionId = typeof options.sessionId === 'string'
132
+ ? options.sessionId
133
+ : options.sessionId !== undefined && options.sessionId !== null
134
+ ? String(options.sessionId)
135
+ : undefined;
136
+ const llmProviders = readHostSettings(ctx, 'llm-pi-ai')?.providers;
137
+ const proModeEnabled = options.purpose === undefined
138
+ && !isCodexConnect
139
+ && isOfficialOpenAiApiRoute(options.provider, options.model, llmProviders)
140
+ && proModeStore.get(sessionId);
124
141
  const contextWindow = options.contextWindow ?? (isCodexConnect ? undefined : settings.contextWindow);
125
142
  const modelMax = typeof options.model === 'string'
126
143
  ? OPENAI_CODEX_MODEL_LIMITS[options.model]?.maxTokens
@@ -162,6 +179,7 @@ export function apply(ctx, config = {}) {
162
179
  if (options.purpose === undefined && isGptModel(options.model)) {
163
180
  return repairLegacyPiAiContextOverflow(hostedWebSearchStream(next, {
164
181
  ...serviceTier === undefined ? {} : { serviceTier },
182
+ ...proModeEnabled ? { reasoningMode: 'pro', backgroundStream: true } : {},
165
183
  hostedWebSearch: !isCodexConnect && resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
166
184
  customApplyPatch: settings.patchToolEnabled,
167
185
  ...trustedCheckpoints === undefined ? {} : { trustedCheckpoints },
@@ -6,7 +6,9 @@ export declare const Config: z<CodexSettings, CodexSettings, 'volatile-defined'>
6
6
  export default class CodexPreferences extends Service {
7
7
  private readonly value;
8
8
  static Config: z<CodexSettings, CodexSettings, "volatile-defined">;
9
+ private readonly listeners;
9
10
  constructor(ctx: Context, value: ReturnType<typeof Config>);
10
11
  current(): CodexSettings;
12
+ subscribe(listener: () => void): () => void;
11
13
  }
12
14
  //# sourceMappingURL=preferences.d.ts.map
@@ -5,12 +5,21 @@ export const Config = CODEX_SETTINGS_SCHEMA.default(CODEX_SETTINGS_ENTRY).volati
5
5
  export default class CodexPreferences extends Service {
6
6
  value;
7
7
  static Config = Config;
8
+ listeners = new Set();
8
9
  constructor(ctx, value) {
9
10
  super(ctx, 'codexPreferences');
10
11
  this.value = value;
12
+ ctx.on?.('loader/volatile-update', () => {
13
+ for (const listener of [...this.listeners])
14
+ listener();
15
+ });
11
16
  }
12
17
  current() {
13
18
  return this.value.get() ?? CODEX_SETTINGS_ENTRY;
14
19
  }
20
+ subscribe(listener) {
21
+ this.listeners.add(listener);
22
+ return () => { this.listeners.delete(listener); };
23
+ }
15
24
  }
16
25
  //# sourceMappingURL=preferences.js.map
@@ -7,7 +7,7 @@ export interface HybridToolSdkSchema extends Readonly<ToolSchema> {
7
7
  readonly output: JsonSchemaNode;
8
8
  }
9
9
  /** Render one supported JSON Schema node to TypeScript, degrading invalid schemas safely. */
10
- export declare function jsonSchemaToTs(schema: unknown, indent?: number): string;
10
+ export declare function jsonSchemaToTs(schema: unknown, indent?: number, toolName?: string): string;
11
11
  /** Render deterministic SDK declarations for hybrid `run_code` bindings. */
12
12
  export declare function renderHybridToolsSdk(schemas: readonly HybridToolSdkSchema[], language?: 'typescript' | 'python', programFormat?: PtcProgramFormat): string;
13
13
  //# sourceMappingURL=hybrid-sdk.d.ts.map