pi-openai-toolkit 0.20.8 → 0.21.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 (54) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +83 -83
  3. package/README.md +8 -26
  4. package/README.zh.md +8 -26
  5. package/config.schema.json +278 -366
  6. package/docs/configuration.md +294 -310
  7. package/docs/internals.md +166 -175
  8. package/package.json +3 -13
  9. package/src/compact-client.ts +412 -389
  10. package/src/compaction-errors.ts +96 -0
  11. package/src/compaction-projection.ts +35 -35
  12. package/src/config/legacy.ts +519 -717
  13. package/src/config/migration.ts +103 -100
  14. package/src/config/notifications.ts +36 -28
  15. package/src/config/policy.ts +10 -18
  16. package/src/config/v2.ts +1167 -1380
  17. package/src/config.ts +310 -319
  18. package/src/context-management/codex-provider.ts +270 -270
  19. package/src/context-management/history-notes.ts +357 -357
  20. package/src/context-management/manual-compact.ts +0 -11
  21. package/src/context-management/tools.ts +371 -371
  22. package/src/context-management/types.ts +168 -168
  23. package/src/context-management/window-manager.ts +801 -801
  24. package/src/debug.ts +238 -237
  25. package/src/deferred-tool-carryover.ts +282 -282
  26. package/src/details-store.ts +151 -151
  27. package/src/extension-runtime.ts +1662 -1616
  28. package/src/image-generation/extension.ts +189 -189
  29. package/src/image-generation/protocol.ts +579 -579
  30. package/src/image-generation/types.ts +300 -300
  31. package/src/payload-rewrite.ts +515 -518
  32. package/src/pi-context-hook.ts +117 -117
  33. package/src/remote-v2-client.ts +811 -814
  34. package/src/request-context-cache.ts +155 -155
  35. package/src/responses-headers.ts +180 -180
  36. package/src/runtime.ts +865 -832
  37. package/src/serializer.ts +882 -882
  38. package/src/supported-environment.ts +27 -27
  39. package/src/types.ts +565 -648
  40. package/src/web-search/alpha-client.ts +876 -876
  41. package/src/web-search/extension.ts +530 -530
  42. package/src/web-search/payload.ts +299 -299
  43. package/src/web-search/prompt.ts +60 -60
  44. package/src/web-search/types.ts +166 -166
  45. package/tsconfig.check.json +50 -54
  46. package/src/auto-mode/classifier.ts +0 -161
  47. package/src/auto-mode/extension.ts +0 -691
  48. package/src/auto-mode/model-selection-guard.ts +0 -52
  49. package/src/auto-mode/policy.ts +0 -146
  50. package/src/auto-mode/prompt.ts +0 -279
  51. package/src/auto-mode/reviewer.ts +0 -325
  52. package/src/auto-mode/tool-review-tui.ts +0 -211
  53. package/src/auto-mode/transcript.ts +0 -135
  54. package/src/auto-mode/types.ts +0 -137
@@ -1,137 +0,0 @@
1
- import type { AutoModeConfig } from "../types";
2
-
3
- export const AUTO_MODE_ENTRY_TYPE = "pi-openai-toolkit.auto-mode-decision.v1";
4
- export const AUTO_MODE_STATUS_KEY = "pi-openai-toolkit:auto-mode";
5
- export const AUTO_MODE_FLAG = "auto";
6
- export const AUTO_MODE_COMMAND = "auto";
7
-
8
- /**
9
- * Built-in tools that change state outside the conversation. Everything else is
10
- * read-only by default and only reviewed when the user opts in through
11
- * `autoMode.extraTools` or `gate: "all"`.
12
- */
13
- export const SIDE_EFFECT_TOOLS = ["bash", "write", "edit"] as const;
14
-
15
- export const MAX_REVIEW_INPUT_CHARS = 8_000;
16
- export const MAX_REVIEW_INTENT_CHARS = 2_000;
17
- export const MAX_REVIEW_REASON_CHARS = 600;
18
- export const MAX_REVIEW_MODEL_KEY_CHARS = 256;
19
-
20
- /** Budgets for the compact transcript handed to the reviewer. */
21
- export const MAX_TRANSCRIPT_CHARS = 24_000;
22
- export const MAX_TRANSCRIPT_TOOL_CHARS = 12_000;
23
- export const MAX_TRANSCRIPT_ENTRY_CHARS = 2_000;
24
- export const MAX_TRANSCRIPT_RECENT_ENTRIES = 40;
25
- export const TRUNCATION_MARKER = "<truncated />";
26
-
27
- /** Risk of the planned action itself, as scored by the reviewer. */
28
- export type RiskLevel = "low" | "medium" | "high" | "critical";
29
-
30
- /** How far the observed conversation actually authorizes that action. */
31
- export type UserAuthorization = "unknown" | "low" | "medium" | "high";
32
-
33
- /**
34
- * Why a review could not be completed. Kept separate from `deny` on purpose: an
35
- * infrastructure failure must never be reported to the agent as a safety verdict.
36
- */
37
- export type ReviewFailureCause =
38
- | "not-configured"
39
- | "timeout"
40
- | "cancelled"
41
- | "provider-error"
42
- | "invalid-output";
43
-
44
- /**
45
- * The reviewer's full verdict. Only `outcome` is required from the model; the
46
- * remaining fields are back-filled by `parseReviewVerdict` so that a terse
47
- * `{"outcome":"allow"}` answer is still a usable, recordable decision.
48
- */
49
- export type GuardianVerdict = {
50
- outcome: "allow" | "deny";
51
- riskLevel: RiskLevel;
52
- userAuthorization: UserAuthorization;
53
- rationale: string;
54
- };
55
-
56
- /**
57
- * Result of asking the reviewer model about one pending tool call.
58
- * `unavailable` means the review could not be completed at all; it is never
59
- * treated as approval.
60
- */
61
- export type ReviewOutcome =
62
- | {
63
- kind: "allow";
64
- verdict: GuardianVerdict;
65
- reviewerModel: string;
66
- evidenceRounds: number;
67
- }
68
- | {
69
- kind: "deny";
70
- verdict: GuardianVerdict;
71
- reviewerModel: string;
72
- evidenceRounds: number;
73
- }
74
- | { kind: "unavailable"; reason: string; cause: ReviewFailureCause };
75
-
76
- /** Non-blocking pre-score produced by the trajectory classifier. */
77
- export type ClassifierRisk = "low" | "high";
78
-
79
- /**
80
- * Why the classifier's cached score could or could not satisfy a gated call.
81
- * Mirrors the deferral reasons the blocking reviewer exists to cover: anything
82
- * other than `low_risk` falls through to the synchronous review.
83
- */
84
- export type FastDecisionReason =
85
- | "low_risk"
86
- | "elevated_risk"
87
- | "stale_score"
88
- | "scoring_failure"
89
- | "missing_score"
90
- | "authorization_changed"
91
- | "requires_synchronous_review";
92
-
93
- export type AutoModeDecisionSource =
94
- | "reviewer"
95
- | "classifier"
96
- | "human"
97
- | "policy"
98
- | "circuit-breaker";
99
-
100
- export type AutoModeDecisionRecord = {
101
- timestamp: number;
102
- toolName: string;
103
- toolCallId: string;
104
- decision:
105
- | "allow"
106
- | "deny"
107
- | "unavailable-allowed"
108
- | "unavailable-blocked"
109
- | "turn-interrupted";
110
- reason: string;
111
- reviewerModel?: string;
112
- source: AutoModeDecisionSource;
113
- /** Present on reviewer verdicts; omitted for classifier fast paths. */
114
- riskLevel?: RiskLevel;
115
- userAuthorization?: UserAuthorization;
116
- evidenceRounds?: number;
117
- /** Only present when `source` is `classifier`. */
118
- fastDecision?: FastDecisionReason;
119
- };
120
-
121
- export type AutoModeModelRef = {
122
- provider?: string;
123
- id?: string;
124
- };
125
-
126
- export type AutoModeGateSource = AutoModeConfig["gate"];
127
-
128
- /**
129
- * Truncate to a bounded single-line-safe diagnostic. Reviewer reasons and tool
130
- * arguments both originate from untrusted text, so every persisted copy is capped.
131
- */
132
- export function boundReviewText(value: unknown, maxChars: number): string {
133
- const text = typeof value === "string" ? value : String(value ?? "");
134
- const collapsed = text.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "").trim();
135
- if (collapsed.length <= maxChars) return collapsed;
136
- return `${collapsed.slice(0, Math.max(0, maxChars - 3))}...`;
137
- }