pi-openai-toolkit 0.23.1 → 0.24.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 (53) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +83 -83
  3. package/README.md +4 -11
  4. package/README.zh.md +4 -11
  5. package/config.schema.json +264 -278
  6. package/docs/configuration.md +304 -298
  7. package/docs/internals.md +98 -181
  8. package/package.json +123 -135
  9. package/src/compact-client.ts +412 -412
  10. package/src/compaction-projection.ts +35 -35
  11. package/src/config/legacy.ts +12 -62
  12. package/src/config/migration.ts +115 -103
  13. package/src/config/notifications.ts +10 -4
  14. package/src/config/policy.ts +9 -10
  15. package/src/config/v2.ts +12 -51
  16. package/src/config.ts +320 -310
  17. package/src/debug.ts +238 -238
  18. package/src/deferred-tool-carryover.ts +282 -282
  19. package/src/details-store.ts +151 -151
  20. package/src/extension-runtime.ts +1095 -1986
  21. package/src/image-generation/extension.ts +189 -189
  22. package/src/image-generation/protocol.ts +579 -579
  23. package/src/image-generation/types.ts +300 -300
  24. package/src/native-fallback.ts +14 -23
  25. package/src/payload-rewrite.ts +515 -515
  26. package/src/pi-context-hook.ts +117 -117
  27. package/src/remote-v2-client.ts +811 -811
  28. package/src/request-context-cache.ts +155 -155
  29. package/src/responses-headers.ts +180 -180
  30. package/src/retired-remote-windows.ts +35 -0
  31. package/src/runtime.ts +875 -865
  32. package/src/serializer.ts +882 -882
  33. package/src/supported-environment.ts +27 -27
  34. package/src/types.ts +541 -565
  35. package/src/web-search/alpha-client.ts +876 -876
  36. package/src/web-search/extension.ts +530 -530
  37. package/src/web-search/payload.ts +299 -299
  38. package/src/web-search/prompt.ts +60 -60
  39. package/src/web-search/types.ts +166 -166
  40. package/tsconfig.check.json +50 -50
  41. package/src/context-management/codex-provider.ts +0 -270
  42. package/src/context-management/history-notes.ts +0 -357
  43. package/src/context-management/manual-compact.ts +0 -599
  44. package/src/context-management/messages.ts +0 -238
  45. package/src/context-management/namespace-tools.ts +0 -426
  46. package/src/context-management/responses-tools.ts +0 -238
  47. package/src/context-management/tool-contract.ts +0 -62
  48. package/src/context-management/tools.ts +0 -371
  49. package/src/context-management/types.ts +0 -168
  50. package/src/context-management/window-budget.ts +0 -83
  51. package/src/context-management/window-bulk.ts +0 -155
  52. package/src/context-management/window-manager.ts +0 -905
  53. package/src/context-management/window-request.ts +0 -125
@@ -1,35 +1,35 @@
1
- import type {
2
- NativeCompactionDetails,
3
- NativeCompactionInputProvenance,
4
- } from "./types";
5
-
6
- /** The configured Pi context-hook projector is unavailable or failed. */
7
- export const COMPACTION_PROJECTION_UNAVAILABLE = "no-supported-projection-seam" as const;
8
- /** The current session context could not be read before projection. */
9
- export const COMPACTION_SESSION_CONTEXT_UNAVAILABLE = "session-context-unavailable" as const;
10
- /** A projected recursive context did not contain the current compaction summary. */
11
- export const COMPACTION_PROJECTED_CONTEXT_UNAVAILABLE = "projected-compaction-context-unavailable" as const;
12
- /** The latest opaque checkpoint was created with no or a different input marker. */
13
- export const COMPACTION_CHECKPOINT_PROVENANCE_UNAVAILABLE = "unverified-compaction-checkpoint" as const;
14
-
15
- /** Persisted edits changed input already sealed inside an opaque checkpoint. */
16
- export const COMPACTION_CHECKPOINT_CONTEXT_EDITED = "checkpoint-context-edited" as const;
17
-
18
- export type UnprojectedCompactionReason =
19
- | typeof COMPACTION_CHECKPOINT_CONTEXT_EDITED
20
- | typeof COMPACTION_PROJECTION_UNAVAILABLE
21
- | typeof COMPACTION_SESSION_CONTEXT_UNAVAILABLE
22
- | typeof COMPACTION_CHECKPOINT_PROVENANCE_UNAVAILABLE
23
- | typeof COMPACTION_PROJECTED_CONTEXT_UNAVAILABLE;
24
-
25
- /**
26
- * A Remote V2 checkpoint is safe for the current replay chain only when its
27
- * marker matches the configured input source. Structural persistence validation
28
- * intentionally remains more permissive for old session files.
29
- */
30
- export function hasVerifiedCompactionInputProvenance(
31
- details: Pick<NativeCompactionDetails, "inputProvenance"> | undefined,
32
- expected: NativeCompactionInputProvenance,
33
- ): boolean {
34
- return details?.inputProvenance === expected;
35
- }
1
+ import type {
2
+ NativeCompactionDetails,
3
+ NativeCompactionInputProvenance,
4
+ } from "./types";
5
+
6
+ /** The configured Pi context-hook projector is unavailable or failed. */
7
+ export const COMPACTION_PROJECTION_UNAVAILABLE = "no-supported-projection-seam" as const;
8
+ /** The current session context could not be read before projection. */
9
+ export const COMPACTION_SESSION_CONTEXT_UNAVAILABLE = "session-context-unavailable" as const;
10
+ /** A projected recursive context did not contain the current compaction summary. */
11
+ export const COMPACTION_PROJECTED_CONTEXT_UNAVAILABLE = "projected-compaction-context-unavailable" as const;
12
+ /** The latest opaque checkpoint was created with no or a different input marker. */
13
+ export const COMPACTION_CHECKPOINT_PROVENANCE_UNAVAILABLE = "unverified-compaction-checkpoint" as const;
14
+
15
+ /** Persisted edits changed input already sealed inside an opaque checkpoint. */
16
+ export const COMPACTION_CHECKPOINT_CONTEXT_EDITED = "checkpoint-context-edited" as const;
17
+
18
+ export type UnprojectedCompactionReason =
19
+ | typeof COMPACTION_CHECKPOINT_CONTEXT_EDITED
20
+ | typeof COMPACTION_PROJECTION_UNAVAILABLE
21
+ | typeof COMPACTION_SESSION_CONTEXT_UNAVAILABLE
22
+ | typeof COMPACTION_CHECKPOINT_PROVENANCE_UNAVAILABLE
23
+ | typeof COMPACTION_PROJECTED_CONTEXT_UNAVAILABLE;
24
+
25
+ /**
26
+ * A Remote V2 checkpoint is safe for the current replay chain only when its
27
+ * marker matches the configured input source. Structural persistence validation
28
+ * intentionally remains more permissive for old session files.
29
+ */
30
+ export function hasVerifiedCompactionInputProvenance(
31
+ details: Pick<NativeCompactionDetails, "inputProvenance"> | undefined,
32
+ expected: NativeCompactionInputProvenance,
33
+ ): boolean {
34
+ return details?.inputProvenance === expected;
35
+ }
@@ -12,8 +12,6 @@ import {
12
12
  THINKING_LEVELS,
13
13
  TOOLKIT_ID,
14
14
  type CompactionConfig,
15
- type ContextManagementMode,
16
- type LeaveManagedModePolicy,
17
15
  type ImageGenerationConfig,
18
16
  type RemoteV2ContextSource,
19
17
  type LoadedToolkitConfig,
@@ -22,7 +20,7 @@ import {
22
20
  type WebSearchConfig,
23
21
  type WebSearchRoute,
24
22
  } from "../types";
25
- import { RETIRED_AUTO_MODE_MESSAGE } from "./policy";
23
+ import { RETIRED_AUTO_MODE_MESSAGE, RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE, RETIRED_REMOTE_WINDOWS_MODE_MESSAGE } from "./policy";
26
24
  import { MAX_IMAGE_MODEL_ID_CHARS } from "../image-generation/types";
27
25
 
28
26
  export const CONFIG_DIR = path.join(os.homedir(), ".pi", "agent", "extensions", TOOLKIT_ID);
@@ -85,34 +83,6 @@ function toBoolean(value: unknown, fieldPath: string, warnings: string[]): boole
85
83
  return undefined;
86
84
  }
87
85
 
88
- function toLeaveManagedMode(
89
- value: unknown,
90
- fieldPath: string,
91
- warnings: string[],
92
- ): LeaveManagedModePolicy | undefined {
93
- if (value === undefined) return undefined;
94
- if (typeof value === "string") {
95
- const normalized = value.trim();
96
- if (normalized === "warn" || normalized === "compact") return normalized;
97
- }
98
- warnings.push(`Ignoring ${fieldPath}: expected one of warn, compact.`);
99
- return undefined;
100
- }
101
-
102
- function toContextManagementMode(
103
- value: unknown,
104
- fieldPath: string,
105
- warnings: string[],
106
- ): ContextManagementMode | undefined {
107
- if (value === undefined) return undefined;
108
- if (typeof value === "string") {
109
- const normalized = value.trim();
110
- if (normalized === "off" || normalized === "remote") return normalized;
111
- }
112
- warnings.push(`Ignoring ${fieldPath}: expected one of off, remote.`);
113
- return undefined;
114
- }
115
-
116
86
  function toRemoteV2ContextSource(
117
87
  value: unknown,
118
88
  fieldPath: string,
@@ -146,21 +116,6 @@ function toThinkingLevel(value: unknown, fieldPath: string, warnings: string[]):
146
116
  return undefined;
147
117
  }
148
118
 
149
- function toBoundedInteger(
150
- value: unknown,
151
- fieldPath: string,
152
- warnings: string[],
153
- min: number,
154
- max: number,
155
- ): number | undefined {
156
- if (value === undefined) return undefined;
157
- if (typeof value === "number" && Number.isInteger(value) && Number.isFinite(value) && value >= min && value <= max) {
158
- return value;
159
- }
160
- warnings.push(`Ignoring ${fieldPath}: expected an integer between ${min} and ${max}.`);
161
- return undefined;
162
- }
163
-
164
119
  function toSupportedApis(
165
120
  value: unknown,
166
121
  fieldPath: string,
@@ -309,12 +264,17 @@ function applyCompactionConfig(
309
264
  warnUnknownFields(raw, COMPACTION_FIELDS, "compaction", warnings);
310
265
 
311
266
  resolved.enabled = toBoolean(raw.enabled, "compaction.enabled", warnings) ?? resolved.enabled;
312
- resolved.contextManagement =
313
- toContextManagementMode(raw.contextManagement, "compaction.contextManagement", warnings) ??
314
- resolved.contextManagement;
315
- resolved.leaveManagedMode =
316
- toLeaveManagedMode(raw.leaveManagedMode, "compaction.leaveManagedMode", warnings) ??
317
- resolved.leaveManagedMode;
267
+ for (const key of ["leaveManagedMode", "contextReminderThresholdPercent"]) {
268
+ if (Object.hasOwn(raw, key)) warnings.push(`Ignoring compaction.${key}: ${RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE}`);
269
+ }
270
+ if (Object.hasOwn(raw, "contextManagement")) {
271
+ const mode = typeof raw.contextManagement === "string" ? raw.contextManagement.trim() : undefined;
272
+ warnings.push(mode === "remote"
273
+ ? `Ignoring compaction.contextManagement: ${RETIRED_REMOTE_WINDOWS_MODE_MESSAGE}`
274
+ : mode === "off"
275
+ ? `Ignoring compaction.contextManagement: ${RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE}`
276
+ : "Ignoring compaction.contextManagement: expected off; remote has been removed.");
277
+ }
318
278
  resolved.allowCompactionContinuityBreak =
319
279
  toBoolean(
320
280
  raw.allowCompactionContinuityBreak,
@@ -323,16 +283,6 @@ function applyCompactionConfig(
323
283
  ) ?? resolved.allowCompactionContinuityBreak;
324
284
  resolved.notifyOnLoad =
325
285
  toBoolean(raw.notifyOnLoad, "compaction.notifyOnLoad", warnings) ?? resolved.notifyOnLoad;
326
- const reminderPercent = toBoundedInteger(
327
- raw.contextReminderThresholdPercent,
328
- "compaction.contextReminderThresholdPercent",
329
- warnings,
330
- 0,
331
- 100,
332
- );
333
- if (reminderPercent !== undefined) {
334
- resolved.contextReminderThresholdPercent = reminderPercent;
335
- }
336
286
  resolved.debug = toBoolean(raw.debug, "compaction.debug", warnings) ?? resolved.debug;
337
287
  resolved.logProviderPayloads =
338
288
  toBoolean(raw.logProviderPayloads, "compaction.logProviderPayloads", warnings) ??
@@ -1,103 +1,115 @@
1
- import { resolveToolkitConfig } from "../config";
2
- import type { LoadedToolkitConfig } from "../types";
3
- import { RETIRED_AUTO_MODE_ISSUE, RETIRED_AUTO_MODE_MESSAGE, type ConfigOrigin } from "./policy";
4
- import { resolveV2Config } from "./v2";
5
-
6
- export type MigrationPreview = {
7
- status: "ready" | "needs-review" | "already-v2" | "unavailable";
8
- candidate?: Record<string, unknown>;
9
- /** Controlled explanations, never arbitrary raw input values. */
10
- reasons: string[];
11
- /** Unknown names are masked; paths never expose unknown values. */
12
- unmappedPaths: string[];
13
- /** Candidate leaf -> origin in the unchanged legacy source (or built-in). */
14
- origins?: Record<string, ConfigOrigin>;
15
- };
16
-
17
- function modelRef(key: string): { provider: string; id: string; api: string } {
18
- const slash = key.indexOf("/");
19
- return { provider: key.slice(0, slash), id: key.slice(slash + 1), api: "openai-responses" };
20
- }
21
-
22
- /** Read-only analysis: never edits a source file or claims a lossy candidate is equivalent. */
23
- export function previewToolkitMigration(loaded: LoadedToolkitConfig): MigrationPreview {
24
- if (loaded.document?.format === "v2") {
25
- const retired = resolveToolkitConfig(loaded).issues.filter((issue) => issue.code === RETIRED_AUTO_MODE_ISSUE);
26
- return { status: "already-v2", reasons: ["The document already uses schemaVersion 2.",
27
- ...(retired.length ? [RETIRED_AUTO_MODE_MESSAGE] : [])], unmappedPaths: retired.map((issue) => issue.path) };
28
- }
29
- if (loaded.document?.format === "invalid" || loaded.document?.format === "missing") {
30
- return { status: "unavailable", reasons: ["A readable legacy document is required; no candidate was produced."], unmappedPaths: [] };
31
- }
32
- const baseline = resolveToolkitConfig(loaded);
33
- const legacy = baseline.config;
34
- const { compatibility: _compatibility, diagnostics, ...defaults } = structuredClone(baseline.policy);
35
- const models: Record<string, unknown> = Object.create(null);
36
- const origins: Record<string, ConfigOrigin> = Object.create(null);
37
- const unmappedPaths = new Set(baseline.issues.map((issue) => issue.path));
38
- for (const [leaf, origin] of Object.entries(baseline.origins)) {
39
- if (leaf.startsWith("compatibility.")) continue;
40
- origins[leaf.startsWith("diagnostics.") ? leaf : `defaults.${leaf}`] = origin;
41
- }
42
- const keys = new Set([
43
- ...legacy.webSearch.models,
44
- ...Object.keys(legacy.webSearch.routes ?? {}),
45
- ...legacy.compaction.gatewayContextModels,
46
- ]);
47
- for (const key of keys) {
48
- const resolved = resolveToolkitConfig(loaded, modelRef(key));
49
- const override: Record<string, unknown> = {};
50
- if (resolved.policy.webSearch.route !== defaults.webSearch.route) override.webSearch = resolved.policy.webSearch;
51
- if (resolved.policy.compatibility.transport !== "standard") override.compatibility = resolved.policy.compatibility;
52
- if (Object.keys(override).length > 0) {
53
- models[key] = override;
54
- for (const [feature, fields] of Object.entries(override)) {
55
- for (const field of Object.keys(fields as Record<string, unknown>)) {
56
- const leaf = `${feature}.${field}`;
57
- origins[`models[${JSON.stringify(key)}].${leaf}`] = resolved.origins[leaf];
58
- }
59
- }
60
- }
61
- }
62
- const candidate = { schemaVersion: 2, defaults, models, diagnostics };
63
- const reasons: string[] = [];
64
- // Retired sections are never migrated; their presence is a controlled removal reason.
65
- if (baseline.issues.some((issue) => issue.code === RETIRED_AUTO_MODE_ISSUE)) {
66
- reasons.push(RETIRED_AUTO_MODE_MESSAGE + " No Auto Mode settings were migrated; review the removal before applying this candidate.");
67
- unmappedPaths.add("autoMode");
68
- }
69
- if (loaded.warnings.length || baseline.issues.length) {
70
- reasons.push("Legacy warnings, unknown fields or normalized invalid values require review. Their original contents remain in the untouched source file.");
71
- }
72
- if (legacy.webSearch.enabled && legacy.webSearch.defaultRoute === undefined &&
73
- legacy.webSearch.models.some((key) => !Object.prototype.hasOwnProperty.call(legacy.webSearch.routes ?? {}, key))) {
74
- reasons.push("Legacy hosted allowlists ignore unsupported APIs and malformed payloads; explicit v2 hosted routes fail closed. This candidate is not behavior-equivalent on those paths.");
75
- }
76
- if (!legacy.webSearch.enabled && (legacy.webSearch.models.length || Object.keys(legacy.webSearch.routes ?? {}).length || legacy.webSearch.defaultRoute)) {
77
- reasons.push("Disabled legacy search contains dormant routes or a model list; simplified v2 policy does not retain that enable-later intent.");
78
- if (legacy.webSearch.models.length) unmappedPaths.add("webSearch.models");
79
- if (Object.keys(legacy.webSearch.routes ?? {}).length) unmappedPaths.add("webSearch.routes");
80
- if (legacy.webSearch.defaultRoute) unmappedPaths.add("webSearch.defaultRoute");
81
- }
82
- if (legacy.webSearch.models.length && (legacy.webSearch.defaultRoute !== undefined ||
83
- legacy.webSearch.models.some((key) => Object.hasOwn(legacy.webSearch.routes ?? {}, key)))) {
84
- unmappedPaths.add("webSearch.models");
85
- }
86
- if (!legacy.compaction.enabled && legacy.compaction.contextManagement === "remote") {
87
- reasons.push("Disabled legacy context management retains a dormant remote mode; the candidate selects Pi ownership.");
88
- unmappedPaths.add("compaction.contextManagement");
89
- }
90
- // Gateway affinity was previously context-mode gated for compaction, and not used by image.
91
- if (legacy.compaction.gatewayContextModels.length) {
92
- reasons.push("Gateway compatibility is now shared across features; review synthetic compaction/image affinity before using this candidate.");
93
- }
94
- const candidateChecks = [resolveV2Config(candidate, undefined), ...[...keys].map((key) => resolveV2Config(candidate, key))];
95
- if (candidateChecks.some((resolved) => resolved.issues.length)) reasons.push("The candidate has v2 validation issues; it cannot be applied as-is.");
96
- return {
97
- status: reasons.length ? "needs-review" : "ready",
98
- candidate,
99
- origins,
100
- unmappedPaths: [...unmappedPaths],
101
- reasons: reasons.length ? reasons : ["Recognized active policies map without a known semantic difference. Preview only; no source file was changed."],
102
- };
103
- }
1
+ import { resolveToolkitConfig } from "../config";
2
+ import type { LoadedToolkitConfig } from "../types";
3
+ import {
4
+ RETIRED_AUTO_MODE_ISSUE, RETIRED_AUTO_MODE_MESSAGE,
5
+ RETIRED_REMOTE_WINDOWS_ISSUE, RETIRED_REMOTE_WINDOWS_MODE_ISSUE,
6
+ RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE, RETIRED_REMOTE_WINDOWS_MODE_MESSAGE,
7
+ type ConfigOrigin,
8
+ } from "./policy";
9
+ import { resolveV2Config } from "./v2";
10
+
11
+ export type MigrationPreview = {
12
+ status: "ready" | "needs-review" | "already-v2" | "unavailable";
13
+ candidate?: Record<string, unknown>;
14
+ /** Controlled explanations, never arbitrary raw input values. */
15
+ reasons: string[];
16
+ /** Unknown names are masked; paths never expose unknown values. */
17
+ unmappedPaths: string[];
18
+ /** Candidate leaf -> origin in the unchanged legacy source (or built-in). */
19
+ origins?: Record<string, ConfigOrigin>;
20
+ };
21
+
22
+ function modelRef(key: string): { provider: string; id: string; api: string } {
23
+ const slash = key.indexOf("/");
24
+ return { provider: key.slice(0, slash), id: key.slice(slash + 1), api: "openai-responses" };
25
+ }
26
+
27
+ /** Read-only analysis: never edits a source file or claims a lossy candidate is equivalent. */
28
+ export function previewToolkitMigration(loaded: LoadedToolkitConfig): MigrationPreview {
29
+ if (loaded.document?.format === "v2") {
30
+ const retired = resolveToolkitConfig(loaded).issues.filter((issue) =>
31
+ [RETIRED_AUTO_MODE_ISSUE, RETIRED_REMOTE_WINDOWS_ISSUE, RETIRED_REMOTE_WINDOWS_MODE_ISSUE].some((code) => code === issue.code));
32
+ const removedMode = retired.some((issue) => issue.code === RETIRED_REMOTE_WINDOWS_MODE_ISSUE);
33
+ return { status: removedMode ? "needs-review" : "already-v2", reasons: ["The document already uses schemaVersion 2.",
34
+ ...(retired.some((issue) => issue.code === RETIRED_AUTO_MODE_ISSUE) ? [RETIRED_AUTO_MODE_MESSAGE] : []),
35
+ ...(retired.some((issue) => issue.code === RETIRED_REMOTE_WINDOWS_ISSUE) ? [RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE] : []),
36
+ ...(removedMode ? [RETIRED_REMOTE_WINDOWS_MODE_MESSAGE] : [])], unmappedPaths: retired.map((issue) => issue.path) };
37
+ }
38
+ if (loaded.document?.format === "invalid" || loaded.document?.format === "missing") {
39
+ return { status: "unavailable", reasons: ["A readable legacy document is required; no candidate was produced."], unmappedPaths: [] };
40
+ }
41
+ const baseline = resolveToolkitConfig(loaded);
42
+ const legacy = baseline.config;
43
+ const { compatibility: _compatibility, diagnostics, ...defaults } = structuredClone(baseline.policy);
44
+ const models: Record<string, unknown> = Object.create(null);
45
+ const origins: Record<string, ConfigOrigin> = Object.create(null);
46
+ const unmappedPaths = new Set(baseline.issues.map((issue) => issue.path));
47
+ for (const [leaf, origin] of Object.entries(baseline.origins)) {
48
+ if (leaf.startsWith("compatibility.")) continue;
49
+ origins[leaf.startsWith("diagnostics.") ? leaf : `defaults.${leaf}`] = origin;
50
+ }
51
+ const keys = new Set([
52
+ ...legacy.webSearch.models,
53
+ ...Object.keys(legacy.webSearch.routes ?? {}),
54
+ ...legacy.compaction.gatewayContextModels,
55
+ ]);
56
+ for (const key of keys) {
57
+ const resolved = resolveToolkitConfig(loaded, modelRef(key));
58
+ const override: Record<string, unknown> = {};
59
+ if (resolved.policy.webSearch.route !== defaults.webSearch.route) override.webSearch = resolved.policy.webSearch;
60
+ if (resolved.policy.compatibility.transport !== "standard") override.compatibility = resolved.policy.compatibility;
61
+ if (Object.keys(override).length > 0) {
62
+ models[key] = override;
63
+ for (const [feature, fields] of Object.entries(override)) {
64
+ for (const field of Object.keys(fields as Record<string, unknown>)) {
65
+ const leaf = `${feature}.${field}`;
66
+ origins[`models[${JSON.stringify(key)}].${leaf}`] = resolved.origins[leaf];
67
+ }
68
+ }
69
+ }
70
+ }
71
+ const candidate = { schemaVersion: 2, defaults, models, diagnostics };
72
+ const reasons: string[] = [];
73
+ // Retired sections are never migrated; their presence is a controlled removal reason.
74
+ if (baseline.issues.some((issue) => issue.code === RETIRED_AUTO_MODE_ISSUE)) {
75
+ reasons.push(RETIRED_AUTO_MODE_MESSAGE + " No Auto Mode settings were migrated; review the removal before applying this candidate.");
76
+ unmappedPaths.add("autoMode");
77
+ }
78
+ if (loaded.warnings.length || baseline.issues.length) {
79
+ reasons.push("Legacy warnings, unknown fields or normalized invalid values require review. Their original contents remain in the untouched source file.");
80
+ }
81
+ if (legacy.webSearch.enabled && legacy.webSearch.defaultRoute === undefined &&
82
+ legacy.webSearch.models.some((key) => !Object.prototype.hasOwnProperty.call(legacy.webSearch.routes ?? {}, key))) {
83
+ reasons.push("Legacy hosted allowlists ignore unsupported APIs and malformed payloads; explicit v2 hosted routes fail closed. This candidate is not behavior-equivalent on those paths.");
84
+ }
85
+ if (!legacy.webSearch.enabled && (legacy.webSearch.models.length || Object.keys(legacy.webSearch.routes ?? {}).length || legacy.webSearch.defaultRoute)) {
86
+ reasons.push("Disabled legacy search contains dormant routes or a model list; simplified v2 policy does not retain that enable-later intent.");
87
+ if (legacy.webSearch.models.length) unmappedPaths.add("webSearch.models");
88
+ if (Object.keys(legacy.webSearch.routes ?? {}).length) unmappedPaths.add("webSearch.routes");
89
+ if (legacy.webSearch.defaultRoute) unmappedPaths.add("webSearch.defaultRoute");
90
+ }
91
+ if (legacy.webSearch.models.length && (legacy.webSearch.defaultRoute !== undefined ||
92
+ legacy.webSearch.models.some((key) => Object.hasOwn(legacy.webSearch.routes ?? {}, key)))) {
93
+ unmappedPaths.add("webSearch.models");
94
+ }
95
+ if (baseline.issues.some((issue) => issue.code === RETIRED_REMOTE_WINDOWS_MODE_ISSUE)) {
96
+ reasons.push(`${RETIRED_REMOTE_WINDOWS_MODE_MESSAGE} The preview uses Pi ownership only as a safe review placeholder; it is not behavior-equivalent. Choose a supported mode explicitly before any manual apply.`);
97
+ unmappedPaths.add("compaction.contextManagement");
98
+ }
99
+ if (baseline.issues.some((issue) => issue.code === RETIRED_REMOTE_WINDOWS_ISSUE)) {
100
+ reasons.push(`${RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE} No retired ancillary settings were migrated; review their removal.`);
101
+ }
102
+ // Gateway affinity is shared across retained compaction and image features.
103
+ if (legacy.compaction.gatewayContextModels.length) {
104
+ reasons.push("Gateway compatibility is now shared across features; review synthetic compaction/image affinity before using this candidate.");
105
+ }
106
+ const candidateChecks = [resolveV2Config(candidate, undefined), ...[...keys].map((key) => resolveV2Config(candidate, key))];
107
+ if (candidateChecks.some((resolved) => resolved.issues.length)) reasons.push("The candidate has v2 validation issues; it cannot be applied as-is.");
108
+ return {
109
+ status: reasons.length ? "needs-review" : "ready",
110
+ candidate,
111
+ origins,
112
+ unmappedPaths: [...unmappedPaths],
113
+ reasons: reasons.length ? reasons : ["Recognized active policies map without a known semantic difference. Preview only; no source file was changed."],
114
+ };
115
+ }
@@ -1,15 +1,21 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import type { ResolvedToolkitConfig } from "../config";
3
- import { RETIRED_AUTO_MODE_ISSUE, RETIRED_AUTO_MODE_MESSAGE, type ConfigIssue } from "./policy";
3
+ import {
4
+ RETIRED_AUTO_MODE_ISSUE, RETIRED_AUTO_MODE_MESSAGE,
5
+ RETIRED_REMOTE_WINDOWS_ISSUE, RETIRED_REMOTE_WINDOWS_MODE_ISSUE,
6
+ RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE, RETIRED_REMOTE_WINDOWS_MODE_MESSAGE,
7
+ type ConfigIssue,
8
+ } from "./policy";
4
9
  import { redactValue } from "../debug";
5
10
 
6
11
  const lastNotice = new WeakMap<object, string>();
7
12
 
8
13
  /** Controlled human text for a known code; never built from user-supplied configuration values. */
9
14
  function issueExplanation(issue: ConfigIssue): string {
10
- return issue.code === RETIRED_AUTO_MODE_ISSUE
11
- ? RETIRED_AUTO_MODE_MESSAGE
12
- : issue.code;
15
+ if (issue.code === RETIRED_AUTO_MODE_ISSUE) return RETIRED_AUTO_MODE_MESSAGE;
16
+ if (issue.code === RETIRED_REMOTE_WINDOWS_ISSUE) return RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE;
17
+ if (issue.code === RETIRED_REMOTE_WINDOWS_MODE_ISSUE) return RETIRED_REMOTE_WINDOWS_MODE_MESSAGE;
18
+ return issue.code;
13
19
  }
14
20
 
15
21
  export function formatConfigIssues(issues: readonly ConfigIssue[], limit = 12): string {
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  DEFAULT_COMPACTION_CONFIG,
3
3
  DEFAULT_IMAGE_GENERATION_MODEL,
4
- type LeaveManagedModePolicy,
5
4
  type NativeFallbackConfig,
6
5
  type RemoteV2ContextSource,
7
6
  } from "../types";
@@ -18,7 +17,7 @@ export type DiagnosticsConfig = {
18
17
  artifactRoot: string;
19
18
  };
20
19
  export type ContextPolicy = {
21
- mode: "pi" | "remote-compaction" | "remote-windows";
20
+ mode: "pi" | "remote-compaction";
22
21
  remoteCompaction: {
23
22
  model: string | null;
24
23
  inputSource: RemoteV2ContextSource;
@@ -26,10 +25,6 @@ export type ContextPolicy = {
26
25
  apis: string[];
27
26
  };
28
27
  nativeFallback: Omit<NativeFallbackConfig, "model"> & { model: string | null };
29
- remoteWindows: {
30
- leaveManagedMode: LeaveManagedModePolicy;
31
- reminderThresholdPercent: number;
32
- };
33
28
  };
34
29
  export type EffectiveToolkitPolicy = {
35
30
  context: ContextPolicy;
@@ -61,6 +56,14 @@ export const RETIRED_AUTO_MODE_ISSUE = "retired.autoMode" as const;
61
56
  /** Controlled explanation of the retirement; never contains user-supplied values. */
62
57
  export const RETIRED_AUTO_MODE_MESSAGE =
63
58
  "Auto Mode has been removed; these settings are ignored and tool calls are no longer reviewed by it.";
59
+ /** Opaque ancillary settings are warning-only; explicitly selected retired modes block context. */
60
+ export const RETIRED_REMOTE_WINDOWS_ISSUE = "retired.remoteWindows" as const;
61
+ export const RETIRED_REMOTE_WINDOWS_MODE_ISSUE = "retired.remoteWindows.mode" as const;
62
+ export const RETIRED_REMOTE_WINDOWS_CONFIG_MESSAGE =
63
+ "Remote Windows has been removed; these settings are ignored. No window behavior or automatic migration is available.";
64
+ export const RETIRED_REMOTE_WINDOWS_MODE_MESSAGE =
65
+ "Remote Windows has been removed. Context operations are blocked until you explicitly select pi or remote-compaction. No replacement mode was activated.";
66
+
64
67
  export type ResolvedToolkitPolicy = {
65
68
  policy: EffectiveToolkitPolicy;
66
69
  origins: Record<string, ConfigOrigin>;
@@ -91,10 +94,6 @@ export function createPolicyDefaults(): EffectiveToolkitPolicy {
91
94
  apis: [...context.responsesApis],
92
95
  },
93
96
  nativeFallback: { ...context.nativeFallback, model: null },
94
- remoteWindows: {
95
- leaveManagedMode: context.leaveManagedMode,
96
- reminderThresholdPercent: context.contextReminderThresholdPercent,
97
- },
98
97
  },
99
98
  webSearch: { route: "unmanaged" },
100
99
  imageGeneration: {
package/src/config/v2.ts CHANGED
@@ -60,6 +60,8 @@ import {
60
60
  import {
61
61
  CONFIG_FEATURES,
62
62
  RETIRED_AUTO_MODE_ISSUE,
63
+ RETIRED_REMOTE_WINDOWS_ISSUE,
64
+ RETIRED_REMOTE_WINDOWS_MODE_ISSUE,
63
65
  createPolicyDefaults,
64
66
  type ConfigFeature,
65
67
  type ConfigIssue,
@@ -100,9 +102,8 @@ export const V2_ISSUE = {
100
102
  imageDefaultNotAllowed: "imageGeneration.defaultModel.notAllowed",
101
103
  } as const;
102
104
 
103
- const CONTEXT_MODES = ["pi", "remote-compaction", "remote-windows"] as const;
105
+ const CONTEXT_MODES = ["pi", "remote-compaction"] as const;
104
106
  const INPUT_SOURCES = ["legacy", "pi-context-hook"] as const;
105
- const LEAVE_MANAGED_MODES = ["warn", "compact"] as const;
106
107
  const SEARCH_ROUTES = ["unmanaged", "local", "hosted", "standalone-alpha"] as const;
107
108
  const TRANSPORTS = ["standard", "codex-gateway"] as const;
108
109
  const DIAGNOSTIC_LEVELS = ["error", "warn", "info", "debug"] as const;
@@ -116,7 +117,6 @@ const MODEL_OVERRIDE_KEYS = new Set(["context", "webSearch", "autoMode", "compat
116
117
  const CONTEXT_KEYS = new Set(["mode", "remoteCompaction", "nativeFallback", "remoteWindows"]);
117
118
  const REMOTE_COMPACTION_KEYS = new Set(["model", "inputSource", "allowContinuityBreak", "apis"]);
118
119
  const NATIVE_FALLBACK_KEYS = new Set(["enabled", "model", "thinkingLevel"]);
119
- const REMOTE_WINDOWS_KEYS = new Set(["leaveManagedMode", "reminderThresholdPercent"]);
120
120
  const WEB_SEARCH_KEYS = new Set(["route"]);
121
121
  const IMAGE_GENERATION_KEYS = new Set(["enabled", "defaultModel", "allowedModels"]);
122
122
  const RESPONSES_WEBSOCKET_KEYS = new Set(["enabled"]);
@@ -165,8 +165,6 @@ const POLICY_LEAVES: readonly { leaf: string; feature: ConfigFeature }[] = [
165
165
  { leaf: "context.nativeFallback.enabled", feature: "context" },
166
166
  { leaf: "context.nativeFallback.model", feature: "context" },
167
167
  { leaf: "context.nativeFallback.thinkingLevel", feature: "context" },
168
- { leaf: "context.remoteWindows.leaveManagedMode", feature: "context" },
169
- { leaf: "context.remoteWindows.reminderThresholdPercent", feature: "context" },
170
168
  { leaf: "webSearch.route", feature: "webSearch" },
171
169
  { leaf: "imageGeneration.enabled", feature: "imageGeneration" },
172
170
  { leaf: "imageGeneration.defaultModel", feature: "imageGeneration" },
@@ -410,16 +408,6 @@ function readEnum<T extends string>(allowed: readonly T[], value: unknown): Read
410
408
  return { ok: false, code: V2_ISSUE.expectedEnum };
411
409
  }
412
410
 
413
- function readInteger(value: unknown, min: number, max: number): ReadResult<number> {
414
- if (typeof value !== "number") {
415
- return { ok: false, code: typeCode(value, V2_ISSUE.expectedInteger) };
416
- }
417
- if (!Number.isInteger(value) || value < min || value > max) {
418
- return { ok: false, code: V2_ISSUE.range };
419
- }
420
- return { ok: true, value };
421
- }
422
-
423
411
  function readThinkingLevel(value: unknown): ReadResult<ThinkingLevel> {
424
412
  return readEnum(THINKING_LEVELS, value);
425
413
  }
@@ -548,7 +536,9 @@ function applyContextSettings(
548
536
  { key: "mode", leaf: "context.mode", feature: "context" },
549
537
  scope,
550
538
  state,
551
- (value) => readEnum(CONTEXT_MODES, value),
539
+ (value) => typeof value === "string" && value.trim() === "remote-windows"
540
+ ? { ok: false, code: RETIRED_REMOTE_WINDOWS_MODE_ISSUE }
541
+ : readEnum(CONTEXT_MODES, value),
552
542
  (value) => {
553
543
  state.policy.context.mode = value;
554
544
  },
@@ -560,8 +550,12 @@ function applyContextSettings(
560
550
  const nativeFallback = openGroup(raw, "nativeFallback", scope, state, "context");
561
551
  if (nativeFallback) applyNativeFallbackSettings(nativeFallback.raw, nativeFallback.scope, state);
562
552
 
563
- const remoteWindows = openGroup(raw, "remoteWindows", scope, state, "context");
564
- if (remoteWindows) applyRemoteWindowsSettings(remoteWindows.raw, remoteWindows.scope, state);
553
+ // Retired ancillary data is opaque, even when malformed. Never validate
554
+ // children, create origins or invalidate otherwise valid context policy.
555
+ if (Object.hasOwn(raw, "remoteWindows")) state.issues.push(withModel(scope, {
556
+ severity: "warning", code: RETIRED_REMOTE_WINDOWS_ISSUE,
557
+ path: joinPath(scope.input, "remoteWindows"), feature: "context",
558
+ }));
565
559
  }
566
560
 
567
561
  function applyRemoteCompactionSettings(
@@ -692,39 +686,6 @@ function applyNativeFallbackSettings(
692
686
  );
693
687
  }
694
688
 
695
- function applyRemoteWindowsSettings(
696
- raw: Record<string, unknown>,
697
- scope: Scope,
698
- state: ResolutionState,
699
- ): void {
700
- reportUnknownKeys(raw, REMOTE_WINDOWS_KEYS, scope, state, "context");
701
-
702
- applyField(
703
- raw,
704
- { key: "leaveManagedMode", leaf: "context.remoteWindows.leaveManagedMode", feature: "context" },
705
- scope,
706
- state,
707
- (value) => readEnum(LEAVE_MANAGED_MODES, value),
708
- (value) => {
709
- state.policy.context.remoteWindows.leaveManagedMode = value;
710
- },
711
- );
712
- applyField(
713
- raw,
714
- {
715
- key: "reminderThresholdPercent",
716
- leaf: "context.remoteWindows.reminderThresholdPercent",
717
- feature: "context",
718
- },
719
- scope,
720
- state,
721
- (value) => readInteger(value, 0, 100),
722
- (value) => {
723
- state.policy.context.remoteWindows.reminderThresholdPercent = value;
724
- },
725
- );
726
- }
727
-
728
689
  function applyWebSearchSettings(
729
690
  raw: Record<string, unknown>,
730
691
  scope: Scope,