@wrongstack/core 0.313.0 → 0.313.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chronicle/index.js +84 -6391
- package/dist/chronicle/project-server.js +84 -4868
- package/dist/chunk-2BUUIMQB.js +225 -0
- package/dist/chunk-2FK4WTFF.js +207 -0
- package/dist/chunk-2FQL4PDC.js +292 -0
- package/dist/chunk-2KKODIQU.js +2256 -0
- package/dist/chunk-2YU4WVBW.js +134 -0
- package/dist/chunk-3E244UDA.js +356 -0
- package/dist/chunk-3XPVB7BA.js +135 -0
- package/dist/chunk-4LJJYBAU.js +388 -0
- package/dist/chunk-4VWO3ZXL.js +342 -0
- package/dist/chunk-4XV6IR37.js +187 -0
- package/dist/chunk-4ZHTKJHM.js +183 -0
- package/dist/chunk-52RTVH4M.js +361 -0
- package/dist/chunk-57GEWK5X.js +26 -0
- package/dist/chunk-5DSMEVA4.js +931 -0
- package/dist/chunk-5RP3QTRL.js +1223 -0
- package/dist/chunk-5S437PRC.js +50 -0
- package/dist/chunk-5XDUGTKN.js +511 -0
- package/dist/chunk-62V2AFVG.js +422 -0
- package/dist/chunk-65RDIOR2.js +2470 -0
- package/dist/chunk-6AKOTGLM.js +597 -0
- package/dist/chunk-7ZHZE5EO.js +28 -0
- package/dist/chunk-A455ATZB.js +140 -0
- package/dist/chunk-AD7ZFZCS.js +46 -0
- package/dist/chunk-AI4LLQ2U.js +856 -0
- package/dist/chunk-ASX6AW36.js +789 -0
- package/dist/chunk-AT4V4XGI.js +3522 -0
- package/dist/chunk-AWNQ6ED6.js +311 -0
- package/dist/chunk-B4AMLZPB.js +9 -0
- package/dist/chunk-BAKVJLEV.js +417 -0
- package/dist/chunk-BJHVULHO.js +55 -0
- package/dist/chunk-CB2HFKTP.js +9 -0
- package/dist/chunk-CE4ZOCOI.js +1640 -0
- package/dist/chunk-CQQL4ZOQ.js +151 -0
- package/dist/chunk-DEIQMBD2.js +65 -0
- package/dist/chunk-E6I5RXVK.js +58 -0
- package/dist/chunk-EFEHDQGY.js +1589 -0
- package/dist/chunk-EODDVJBM.js +82 -0
- package/dist/chunk-EPC3GZD4.js +308 -0
- package/dist/chunk-FAYRX2AD.js +13 -0
- package/dist/chunk-FFSX2QDQ.js +362 -0
- package/dist/chunk-FHAMQS7Q.js +5856 -0
- package/dist/chunk-FIV4IJL7.js +2263 -0
- package/dist/chunk-FNXVT7HF.js +52 -0
- package/dist/chunk-FSWCWSTS.js +395 -0
- package/dist/chunk-FW5LDDMJ.js +16464 -0
- package/dist/chunk-FXQLIX3K.js +211 -0
- package/dist/chunk-G5AAKEEZ.js +228 -0
- package/dist/chunk-G5S3S5ZN.js +38 -0
- package/dist/chunk-GAZEWQEZ.js +231 -0
- package/dist/chunk-GFJOMSHG.js +125 -0
- package/dist/chunk-GFXZTHNI.js +158 -0
- package/dist/chunk-GM54GJBU.js +960 -0
- package/dist/chunk-GPQ3NJPR.js +900 -0
- package/dist/chunk-GTCU6DZ3.js +1 -0
- package/dist/chunk-H5E77KUJ.js +15 -0
- package/dist/chunk-H72H4XDU.js +1023 -0
- package/dist/chunk-HA4ZYA6T.js +178 -0
- package/dist/chunk-I45KAW2N.js +5020 -0
- package/dist/chunk-IQ35HMQL.js +1396 -0
- package/dist/chunk-IYFBFX34.js +86 -0
- package/dist/chunk-JJPMWPB6.js +109 -0
- package/dist/chunk-JTHKOYWU.js +663 -0
- package/dist/chunk-JVGPR3TS.js +365 -0
- package/dist/chunk-JVKB2TBL.js +48 -0
- package/dist/chunk-JX7VBZDK.js +31 -0
- package/dist/chunk-K3G6JBUC.js +5232 -0
- package/dist/chunk-K4YUNKU7.js +589 -0
- package/dist/chunk-KBZGE6LN.js +710 -0
- package/dist/chunk-KDQJCT2J.js +45 -0
- package/dist/chunk-KI4L2DUL.js +560 -0
- package/dist/chunk-KJ2ZTQSL.js +47 -0
- package/dist/chunk-KSJ5UTP7.js +154 -0
- package/dist/chunk-LHOA5DWA.js +28 -0
- package/dist/chunk-LX5QWLBL.js +27 -0
- package/dist/chunk-LZDDLNCZ.js +279 -0
- package/dist/chunk-M2WF6AXG.js +115 -0
- package/dist/chunk-M7BS2K6U.js +1 -0
- package/dist/chunk-NDBIPFNY.js +102 -0
- package/dist/chunk-NEMIWEXC.js +1199 -0
- package/dist/chunk-NFAYHPRH.js +323 -0
- package/dist/chunk-O37BQ65S.js +21 -0
- package/dist/chunk-O74MJHXU.js +187 -0
- package/dist/chunk-OJZEX73F.js +112 -0
- package/dist/chunk-PAAWLLZX.js +74 -0
- package/dist/chunk-PFXFQQRT.js +339 -0
- package/dist/chunk-PFZO3C6H.js +14 -0
- package/dist/chunk-PHH7LD45.js +113 -0
- package/dist/chunk-QRTG4XTI.js +188 -0
- package/dist/chunk-QVOVMXJR.js +1351 -0
- package/dist/chunk-RCQYT2I4.js +757 -0
- package/dist/chunk-RD6DEE36.js +1178 -0
- package/dist/chunk-RJIZEJ42.js +30 -0
- package/dist/chunk-RPOA7IAE.js +150 -0
- package/dist/chunk-SN2DQRL6.js +1172 -0
- package/dist/chunk-SQJVFEBV.js +41 -0
- package/dist/chunk-SQP64RCS.js +5391 -0
- package/dist/chunk-SVT4RNTR.js +49 -0
- package/dist/chunk-SWUFN7XM.js +43 -0
- package/dist/chunk-SXMVYC5H.js +174 -0
- package/dist/chunk-SZ6AYUIZ.js +23 -0
- package/dist/chunk-T3KGZBU5.js +3171 -0
- package/dist/chunk-TBRL2RCC.js +9 -0
- package/dist/chunk-TRT2HRWZ.js +18 -0
- package/dist/chunk-TYW2GI5I.js +1077 -0
- package/dist/chunk-UIWONWVG.js +4959 -0
- package/dist/chunk-VB3H5WWB.js +151 -0
- package/dist/chunk-W4A6QA3D.js +258 -0
- package/dist/chunk-WBPVKEEE.js +227 -0
- package/dist/chunk-WEBMSQP2.js +123 -0
- package/dist/chunk-WOEZV3Q4.js +333 -0
- package/dist/chunk-WQQON3SV.js +473 -0
- package/dist/chunk-WQTOVMGV.js +119 -0
- package/dist/chunk-WZO23AWO.js +2779 -0
- package/dist/chunk-XBDP4QPW.js +7 -0
- package/dist/chunk-XEBHSJLT.js +103 -0
- package/dist/chunk-XQ2ECNK3.js +1 -0
- package/dist/chunk-XQ2XGIBF.js +2086 -0
- package/dist/chunk-Y2GE5TSI.js +355 -0
- package/dist/chunk-YBUJCZ57.js +351 -0
- package/dist/chunk-YNCVSFGF.js +149 -0
- package/dist/chunk-YUPMXOGP.js +282 -0
- package/dist/chunk-YY6APYUM.js +49 -0
- package/dist/chunk-Z2IJUO45.js +691 -0
- package/dist/chunk-ZEHUCJHY.js +129 -0
- package/dist/chunk-ZYU2YOJ6.js +1496 -0
- package/dist/chunk-ZZ4V3WIZ.js +163 -0
- package/dist/coordination/agents/index.js +145 -6260
- package/dist/coordination/index.js +365 -34324
- package/dist/coordination/mailbox-project-server.js +48 -3276
- package/dist/coordination/provider-status-tracker.d.ts +4 -0
- package/dist/core/agent.d.ts +14 -1
- package/dist/core/index.js +267 -12480
- package/dist/core/model-ref.js +5 -23
- package/dist/core/provider-runner.d.ts +36 -1
- package/dist/design/index.js +50 -1087
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.js +1599 -21888
- package/dist/execution/prompt-enhancer.js +16 -535
- package/dist/execution/retry-policy.d.ts +31 -1
- package/dist/extension/index.js +7 -311
- package/dist/goal/index.js +33 -3435
- package/dist/hooks/index.js +14 -1138
- package/dist/hq/index.js +112 -5139
- package/dist/hq/protocol.js +21 -668
- package/dist/index.js +1410 -92656
- package/dist/infrastructure/index.js +64 -4811
- package/dist/kernel/events/provider-events.d.ts +15 -0
- package/dist/kernel/index.js +14 -992
- package/dist/models/index.js +40 -1117
- package/dist/notifications/index.js +3 -108
- package/dist/observability/index.js +17 -279
- package/dist/plugin/index.js +584 -14835
- package/dist/prompts/index.js +14 -948
- package/dist/registry/index.js +9 -822
- package/dist/registry-R23UBE7H.js +14 -0
- package/dist/replay/index.js +6 -84
- package/dist/review-finding-store-DKAV3AS6.js +21 -0
- package/dist/review-report-store-OWY3EC3N.js +19 -0
- package/dist/security/index.js +114 -2202
- package/dist/session-catalog/index.js +36 -2103
- package/dist/session-catalog/project-server.js +42 -1435
- package/dist/skills/index.js +35 -1578
- package/dist/storage/index.js +182 -15600
- package/dist/tasking/index.js +10 -676
- package/dist/tools/index.js +52 -9590
- package/dist/types/config/autonomy.d.ts +5 -0
- package/dist/types/config/ui.d.ts +1 -1
- package/dist/types/errors.d.ts +18 -0
- package/dist/types/index.js +121 -1342
- package/dist/types/provider-runner.d.ts +8 -0
- package/dist/types/session-markers.js +8 -144
- package/dist/utils/error.js +3 -4
- package/dist/utils/expect-defined.js +3 -9
- package/dist/utils/heap-watchdog.js +6 -706
- package/dist/utils/index.js +269 -5685
- package/dist/utils/sage-output-block.js +5 -42
- package/dist/wiring/proxy-rewrite.d.ts +18 -0
- package/dist/wiring/proxy-rewrite.js +18 -121
- package/dist/worktree/index.js +6 -887
- package/package.json +4 -4
package/dist/types/index.js
CHANGED
|
@@ -1,1345 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
id: "balanced",
|
|
123
|
-
name: "Balanced",
|
|
124
|
-
description: "Default rolling compaction: recent work stays verbatim, old tool output is trimmed. Windows of 1M+ tokens default to Deep.",
|
|
125
|
-
thresholds: { warn: 0.55, soft: 0.7, hard: 0.85 },
|
|
126
|
-
aggressiveOn: "soft",
|
|
127
|
-
preserveK: 8,
|
|
128
|
-
eliseThreshold: 1200,
|
|
129
|
-
targetLoad: 0.65
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
id: "frugal",
|
|
133
|
-
name: "Frugal",
|
|
134
|
-
description: "Token-saver mode: compacts early and keeps a tight verbatim tail.",
|
|
135
|
-
thresholds: { warn: 0.4, soft: 0.55, hard: 0.7 },
|
|
136
|
-
aggressiveOn: "warn",
|
|
137
|
-
preserveK: 4,
|
|
138
|
-
eliseThreshold: 500,
|
|
139
|
-
targetLoad: 0.45
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
id: "deep",
|
|
143
|
-
name: "Deep",
|
|
144
|
-
description: "Long-reasoning mode: delays compaction and keeps more recent turns intact.",
|
|
145
|
-
thresholds: { warn: 0.72, soft: 0.86, hard: 0.96 },
|
|
146
|
-
aggressiveOn: "hard",
|
|
147
|
-
preserveK: 18,
|
|
148
|
-
eliseThreshold: 5e3,
|
|
149
|
-
targetLoad: 0.82
|
|
150
|
-
}
|
|
151
|
-
]);
|
|
152
|
-
function listContextWindowModes() {
|
|
153
|
-
return CONTEXT_WINDOW_MODES.map((m) => ({ ...m, thresholds: { ...m.thresholds } }));
|
|
154
|
-
}
|
|
155
|
-
function normalizeContextWindowModeId(id) {
|
|
156
|
-
if (!id) return null;
|
|
157
|
-
if (isContextWindowModeId(id)) return id;
|
|
158
|
-
return DEPRECATED_CONTEXT_WINDOW_MODE_ALIASES[id] ?? null;
|
|
159
|
-
}
|
|
160
|
-
function isDeprecatedContextWindowModeId(id) {
|
|
161
|
-
return Object.hasOwn(DEPRECATED_CONTEXT_WINDOW_MODE_ALIASES, id);
|
|
162
|
-
}
|
|
163
|
-
function isContextWindowModeSelectionId(id) {
|
|
164
|
-
return isContextWindowModeId(id) || isDeprecatedContextWindowModeId(id);
|
|
165
|
-
}
|
|
166
|
-
function getContextWindowMode(id) {
|
|
167
|
-
const normalized = normalizeContextWindowModeId(id);
|
|
168
|
-
if (!normalized) return null;
|
|
169
|
-
const mode = CONTEXT_WINDOW_MODES.find((m) => m.id === normalized);
|
|
170
|
-
return mode ? { ...mode, thresholds: { ...mode.thresholds } } : null;
|
|
171
|
-
}
|
|
172
|
-
function isContextWindowModeId(id) {
|
|
173
|
-
return CONTEXT_WINDOW_MODES.some((m) => m.id === id);
|
|
174
|
-
}
|
|
175
|
-
function resolveContextWindowPolicy(config = {}, overrideMode, maxContext) {
|
|
176
|
-
const requested = overrideMode ?? config.mode ?? DEFAULT_CONTEXT_WINDOW_MODE_ID;
|
|
177
|
-
const normalized = normalizeContextWindowModeId(requested) ?? DEFAULT_CONTEXT_WINDOW_MODE_ID;
|
|
178
|
-
const baseId = normalized === DEFAULT_CONTEXT_WINDOW_MODE_ID && typeof maxContext === "number" && maxContext >= LARGE_WINDOW_DEEP_MODE_THRESHOLD ? "deep" : normalized;
|
|
179
|
-
const mode = expectDefined(getContextWindowMode(baseId));
|
|
180
|
-
return {
|
|
181
|
-
...mode,
|
|
182
|
-
thresholds: {
|
|
183
|
-
warn: config.warnThreshold ?? mode.thresholds.warn,
|
|
184
|
-
soft: config.softThreshold ?? mode.thresholds.soft,
|
|
185
|
-
hard: config.hardThreshold ?? mode.thresholds.hard
|
|
186
|
-
},
|
|
187
|
-
preserveK: config.preserveK ?? mode.preserveK,
|
|
188
|
-
eliseThreshold: config.eliseThreshold ?? mode.eliseThreshold,
|
|
189
|
-
targetLoad: config.targetLoad ?? mode.targetLoad
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
function formatContextWindowModeList(activeId) {
|
|
193
|
-
const active = normalizeContextWindowModeId(activeId);
|
|
194
|
-
return CONTEXT_WINDOW_MODES.map((m) => {
|
|
195
|
-
const marker = m.id === active ? "*" : " ";
|
|
196
|
-
return `${marker} ${m.id.padEnd(9)} ${m.name} - ${m.description}`;
|
|
197
|
-
}).join("\n");
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// src/types/default-config.ts
|
|
201
|
-
var DEFAULT_TOOLS_CONFIG = Object.freeze({
|
|
202
|
-
defaultExecutionStrategy: "smart",
|
|
203
|
-
maxIterations: 100,
|
|
204
|
-
iterationTimeoutMs: 3e5,
|
|
205
|
-
maxToolTimeoutMs: 3e5,
|
|
206
|
-
sessionTimeoutMs: 18e5,
|
|
207
|
-
perIterationOutputCapBytes: 1e5,
|
|
208
|
-
descriptionMode: Object.freeze({}),
|
|
209
|
-
disabledTools: Object.freeze([]),
|
|
210
|
-
// Extension requires an explicit host/user policy. Without that boundary a
|
|
211
|
-
// nominal maxIterations cap can grow forever in autonomous sessions.
|
|
212
|
-
autoExtendLimit: false,
|
|
213
|
-
restrictToProjectRoot: true,
|
|
214
|
-
// Off by default: the board is a record of the work, not a permit for it.
|
|
215
|
-
// See ToolsConfig.kanbanGovernance for what turning it on costs and gates.
|
|
216
|
-
kanbanGovernance: false,
|
|
217
|
-
loopDetection: Object.freeze({
|
|
218
|
-
mode: "steer-then-cut",
|
|
219
|
-
steerThreshold: 3,
|
|
220
|
-
cutThreshold: 5,
|
|
221
|
-
windowSize: 12,
|
|
222
|
-
callRepeatThreshold: 4
|
|
223
|
-
})
|
|
224
|
-
});
|
|
225
|
-
var DEFAULT_CONTEXT_CONFIG = Object.freeze({
|
|
226
|
-
warnThreshold: 0.55,
|
|
227
|
-
softThreshold: 0.7,
|
|
228
|
-
hardThreshold: 0.85,
|
|
229
|
-
targetLoad: 0.65,
|
|
230
|
-
preserveK: 8,
|
|
231
|
-
eliseThreshold: 1200
|
|
232
|
-
});
|
|
233
|
-
var DEFAULT_AUTONOMY_CONFIG = Object.freeze({
|
|
234
|
-
autoProceedDelayMs: 45e3
|
|
235
|
-
});
|
|
236
|
-
var DEFAULT_CIRCUIT_BREAKER_CONFIG = Object.freeze({
|
|
237
|
-
enabled: false,
|
|
238
|
-
autoKillResetMs: 6e4
|
|
239
|
-
});
|
|
240
|
-
var DEFAULT_SESSION_LOGGING_CONFIG = Object.freeze({
|
|
241
|
-
auditLevel: "standard",
|
|
242
|
-
sampling: {
|
|
243
|
-
toolProgress: {
|
|
244
|
-
sampleRate: 8
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
var DEFAULT_SESSION_PRUNE_DAYS = 30;
|
|
249
|
-
|
|
250
|
-
// src/types/design-kit.ts
|
|
251
|
-
var DESIGN_STACKS = ["web", "react-native", "flutter", "swiftui", "compose"];
|
|
252
|
-
function isDesignStack(v) {
|
|
253
|
-
return DESIGN_STACKS.includes(v);
|
|
254
|
-
}
|
|
255
|
-
var KNOWN_TOKEN_GROUPS = {
|
|
256
|
-
/** Corner radii. */
|
|
257
|
-
radius: ["radius-none", "radius-sm", "radius-md", "radius-lg", "radius-xl", "radius-full"],
|
|
258
|
-
/** Spacing scale (4/8px rhythm). */
|
|
259
|
-
space: ["space-1", "space-2", "space-3", "space-4", "space-6", "space-8", "space-12"],
|
|
260
|
-
/** Type sizes. */
|
|
261
|
-
text: ["text-xs", "text-sm", "text-base", "text-lg", "text-xl", "text-2xl", "text-3xl"],
|
|
262
|
-
/** Line-heights (unitless). */
|
|
263
|
-
leading: ["leading-tight", "leading-normal", "leading-relaxed"],
|
|
264
|
-
/** Font weights (unitless). */
|
|
265
|
-
weight: ["weight-normal", "weight-medium", "weight-semibold", "weight-bold"],
|
|
266
|
-
/** Letter-spacing. */
|
|
267
|
-
tracking: ["tracking-tight", "tracking-normal", "tracking-wide"],
|
|
268
|
-
/** Elevation / shadow ramp. */
|
|
269
|
-
shadow: ["shadow-1", "shadow-2", "shadow-3", "shadow-4"],
|
|
270
|
-
/** Border widths. */
|
|
271
|
-
border: ["border-hairline", "border-thin", "border-thick"],
|
|
272
|
-
/** Motion durations. */
|
|
273
|
-
duration: ["duration-fast", "duration-base", "duration-slow"],
|
|
274
|
-
/** Motion easings. */
|
|
275
|
-
ease: ["ease-standard", "ease-emphasized"],
|
|
276
|
-
/** Font families. */
|
|
277
|
-
font: ["font-sans", "font-mono", "font-display"]
|
|
278
|
-
};
|
|
279
|
-
var KNOWN_TOKEN_NAMES = Object.values(KNOWN_TOKEN_GROUPS).flat();
|
|
280
|
-
|
|
281
|
-
// src/utils/error.ts
|
|
282
|
-
function toErrorMessage(err) {
|
|
283
|
-
return err instanceof Error ? err.message : String(err);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// src/types/errors.ts
|
|
287
|
-
var ERROR_CODES = {
|
|
288
|
-
// Provider
|
|
289
|
-
PROVIDER_RATE_LIMITED: "PROVIDER_RATE_LIMITED",
|
|
290
|
-
PROVIDER_AUTH_FAILED: "PROVIDER_AUTH_FAILED",
|
|
291
|
-
PROVIDER_OVERLOADED: "PROVIDER_OVERLOADED",
|
|
292
|
-
PROVIDER_INVALID_REQUEST: "PROVIDER_INVALID_REQUEST",
|
|
293
|
-
PROVIDER_SERVER_ERROR: "PROVIDER_SERVER_ERROR",
|
|
294
|
-
PROVIDER_NETWORK_ERROR: "PROVIDER_NETWORK_ERROR",
|
|
295
|
-
PROVIDER_CONTEXT_OVERFLOW: "PROVIDER_CONTEXT_OVERFLOW",
|
|
296
|
-
// Tool
|
|
297
|
-
TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
|
|
298
|
-
TOOL_PERMISSION_DENIED: "TOOL_PERMISSION_DENIED",
|
|
299
|
-
TOOL_EXECUTION_FAILED: "TOOL_EXECUTION_FAILED",
|
|
300
|
-
TOOL_TIMEOUT: "TOOL_TIMEOUT",
|
|
301
|
-
TOOL_INPUT_INVALID: "TOOL_INPUT_INVALID",
|
|
302
|
-
// Config
|
|
303
|
-
CONFIG_INVALID: "CONFIG_INVALID",
|
|
304
|
-
CONFIG_NOT_FOUND: "CONFIG_NOT_FOUND",
|
|
305
|
-
CONFIG_PARSE_FAILED: "CONFIG_PARSE_FAILED",
|
|
306
|
-
CONFIG_MIGRATION_NEEDED: "CONFIG_MIGRATION_NEEDED",
|
|
307
|
-
// Plugin
|
|
308
|
-
PLUGIN_LOAD_FAILED: "PLUGIN_LOAD_FAILED",
|
|
309
|
-
PLUGIN_API_MISMATCH: "PLUGIN_API_MISMATCH",
|
|
310
|
-
PLUGIN_MISSING_DEPENDENCY: "PLUGIN_MISSING_DEPENDENCY",
|
|
311
|
-
// Agent
|
|
312
|
-
AGENT_ITERATION_LIMIT: "AGENT_ITERATION_LIMIT",
|
|
313
|
-
AGENT_CONTEXT_OVERFLOW: "AGENT_CONTEXT_OVERFLOW",
|
|
314
|
-
AGENT_ABORTED: "AGENT_ABORTED",
|
|
315
|
-
AGENT_RUN_FAILED: "AGENT_RUN_FAILED",
|
|
316
|
-
// Session
|
|
317
|
-
SESSION_NOT_FOUND: "SESSION_NOT_FOUND",
|
|
318
|
-
SESSION_CORRUPTED: "SESSION_CORRUPTED",
|
|
319
|
-
SESSION_WRITE_FAILED: "SESSION_WRITE_FAILED",
|
|
320
|
-
// Container / Registry
|
|
321
|
-
CONTAINER_TOKEN_ALREADY_BOUND: "CONTAINER_TOKEN_ALREADY_BOUND",
|
|
322
|
-
CONTAINER_TOKEN_NOT_BOUND: "CONTAINER_TOKEN_NOT_BOUND",
|
|
323
|
-
CONTAINER_CIRCULAR_DEPENDENCY: "CONTAINER_CIRCULAR_DEPENDENCY",
|
|
324
|
-
REGISTRY_DUPLICATE: "REGISTRY_DUPLICATE",
|
|
325
|
-
REGISTRY_NOT_FOUND: "REGISTRY_NOT_FOUND",
|
|
326
|
-
REGISTRY_INVALID: "REGISTRY_INVALID",
|
|
327
|
-
// File system
|
|
328
|
-
FS_READ_FAILED: "FS_READ_FAILED",
|
|
329
|
-
FS_WRITE_FAILED: "FS_WRITE_FAILED",
|
|
330
|
-
FS_MKDIR_FAILED: "FS_MKDIR_FAILED",
|
|
331
|
-
FS_DELETE_FAILED: "FS_DELETE_FAILED",
|
|
332
|
-
FS_ATOMIC_WRITE_FAILED: "FS_ATOMIC_WRITE_FAILED",
|
|
333
|
-
// SDD (Spec-Driven Development)
|
|
334
|
-
SDD_VALIDATION_FAILED: "SDD_VALIDATION_FAILED",
|
|
335
|
-
SDD_PARSE_FAILED: "SDD_PARSE_FAILED",
|
|
336
|
-
SDD_INVALID_STATE: "SDD_INVALID_STATE",
|
|
337
|
-
SDD_NOT_READY: "SDD_NOT_READY",
|
|
338
|
-
// General
|
|
339
|
-
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
340
|
-
PARSE_FAILED: "PARSE_FAILED",
|
|
341
|
-
UNKNOWN: "UNKNOWN"
|
|
342
|
-
};
|
|
343
|
-
var WrongStackError = class extends Error {
|
|
344
|
-
code;
|
|
345
|
-
subsystem;
|
|
346
|
-
severity;
|
|
347
|
-
recoverable;
|
|
348
|
-
context;
|
|
349
|
-
constructor(opts) {
|
|
350
|
-
super(opts.message, { cause: opts.cause });
|
|
351
|
-
this.name = "WrongStackError";
|
|
352
|
-
this.code = opts.code;
|
|
353
|
-
this.subsystem = opts.subsystem;
|
|
354
|
-
this.severity = opts.severity ?? "error";
|
|
355
|
-
this.recoverable = opts.recoverable ?? false;
|
|
356
|
-
this.context = opts.context;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Render a one-line user-facing description.
|
|
360
|
-
* Subclasses should override for domain-specific formatting.
|
|
361
|
-
*/
|
|
362
|
-
describe() {
|
|
363
|
-
const ctx = this.context ? ` ${formatContext(this.context)}` : "";
|
|
364
|
-
return `${this.code}: ${this.message}${ctx}`;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
function formatContext(ctx) {
|
|
368
|
-
const parts = Object.entries(ctx).filter(([, v]) => v !== void 0).slice(0, 3).map(([k, v]) => `${k}=${String(v)}`);
|
|
369
|
-
return parts.length > 0 ? `[${parts.join(" ")}]` : "";
|
|
370
|
-
}
|
|
371
|
-
var ToolError = class extends WrongStackError {
|
|
372
|
-
toolName;
|
|
373
|
-
constructor(opts) {
|
|
374
|
-
super({
|
|
375
|
-
message: opts.message,
|
|
376
|
-
code: opts.code,
|
|
377
|
-
subsystem: "tool",
|
|
378
|
-
recoverable: opts.recoverable,
|
|
379
|
-
context: { tool: opts.toolName, ...opts.context },
|
|
380
|
-
cause: opts.cause
|
|
381
|
-
});
|
|
382
|
-
this.name = "ToolError";
|
|
383
|
-
this.toolName = opts.toolName;
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
var ConfigError = class extends WrongStackError {
|
|
387
|
-
constructor(opts) {
|
|
388
|
-
super({
|
|
389
|
-
message: opts.message,
|
|
390
|
-
code: opts.code,
|
|
391
|
-
subsystem: "config",
|
|
392
|
-
severity: "fatal",
|
|
393
|
-
recoverable: false,
|
|
394
|
-
context: opts.context,
|
|
395
|
-
cause: opts.cause
|
|
396
|
-
});
|
|
397
|
-
this.name = "ConfigError";
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
var PluginError = class extends WrongStackError {
|
|
401
|
-
pluginName;
|
|
402
|
-
constructor(opts) {
|
|
403
|
-
super({
|
|
404
|
-
message: opts.message,
|
|
405
|
-
code: opts.code,
|
|
406
|
-
subsystem: "plugin",
|
|
407
|
-
severity: "error",
|
|
408
|
-
recoverable: opts.code === ERROR_CODES.PLUGIN_MISSING_DEPENDENCY,
|
|
409
|
-
context: { plugin: opts.pluginName, ...opts.context },
|
|
410
|
-
cause: opts.cause
|
|
411
|
-
});
|
|
412
|
-
this.name = "PluginError";
|
|
413
|
-
this.pluginName = opts.pluginName;
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
var AgentError = class extends WrongStackError {
|
|
417
|
-
constructor(opts) {
|
|
418
|
-
super({
|
|
419
|
-
message: opts.message,
|
|
420
|
-
code: opts.code,
|
|
421
|
-
subsystem: "agent",
|
|
422
|
-
severity: opts.code === ERROR_CODES.AGENT_ABORTED ? "warning" : "error",
|
|
423
|
-
recoverable: opts.recoverable ?? opts.code === ERROR_CODES.AGENT_ITERATION_LIMIT,
|
|
424
|
-
context: opts.context,
|
|
425
|
-
cause: opts.cause
|
|
426
|
-
});
|
|
427
|
-
this.name = "AgentError";
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
function toWrongStackError(err, code = ERROR_CODES.AGENT_RUN_FAILED) {
|
|
431
|
-
if (err instanceof WrongStackError) return err;
|
|
432
|
-
const message = toErrorMessage(err);
|
|
433
|
-
return new AgentError({
|
|
434
|
-
message,
|
|
435
|
-
code: code === "UNKNOWN" ? ERROR_CODES.AGENT_RUN_FAILED : code,
|
|
436
|
-
cause: err
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
var SessionError = class extends WrongStackError {
|
|
440
|
-
sessionId;
|
|
441
|
-
constructor(opts) {
|
|
442
|
-
super({
|
|
443
|
-
message: opts.message,
|
|
444
|
-
code: opts.code,
|
|
445
|
-
subsystem: "session",
|
|
446
|
-
severity: opts.code === ERROR_CODES.SESSION_WRITE_FAILED ? "error" : "warning",
|
|
447
|
-
recoverable: opts.code !== ERROR_CODES.SESSION_CORRUPTED,
|
|
448
|
-
context: { sessionId: opts.sessionId, ...opts.context },
|
|
449
|
-
cause: opts.cause
|
|
450
|
-
});
|
|
451
|
-
this.name = "SessionError";
|
|
452
|
-
this.sessionId = opts.sessionId;
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
var SddError = class extends WrongStackError {
|
|
456
|
-
constructor(opts) {
|
|
457
|
-
super({
|
|
458
|
-
message: opts.message,
|
|
459
|
-
code: opts.code,
|
|
460
|
-
subsystem: "sdd",
|
|
461
|
-
severity: opts.code === ERROR_CODES.SDD_PARSE_FAILED ? "warning" : "error",
|
|
462
|
-
recoverable: opts.code === ERROR_CODES.SDD_NOT_READY,
|
|
463
|
-
context: opts.context,
|
|
464
|
-
cause: opts.cause
|
|
465
|
-
});
|
|
466
|
-
this.name = "SddError";
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
var FsError = class extends WrongStackError {
|
|
470
|
-
path;
|
|
471
|
-
constructor(opts) {
|
|
472
|
-
super({
|
|
473
|
-
message: opts.message,
|
|
474
|
-
code: opts.code,
|
|
475
|
-
subsystem: "fs",
|
|
476
|
-
severity: "error",
|
|
477
|
-
recoverable: opts.code !== ERROR_CODES.FS_READ_FAILED,
|
|
478
|
-
context: { path: opts.path, ...opts.context },
|
|
479
|
-
cause: opts.cause
|
|
480
|
-
});
|
|
481
|
-
this.name = "FsError";
|
|
482
|
-
this.path = opts.path;
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
var FetchError = class extends WrongStackError {
|
|
486
|
-
status;
|
|
487
|
-
constructor(opts) {
|
|
488
|
-
super({
|
|
489
|
-
message: opts.message,
|
|
490
|
-
code: ERROR_CODES.VALIDATION_ERROR,
|
|
491
|
-
subsystem: "general",
|
|
492
|
-
severity: "error",
|
|
493
|
-
recoverable: opts.status === 429 || opts.status >= 500,
|
|
494
|
-
context: { status: opts.status, ...opts.context },
|
|
495
|
-
cause: opts.cause
|
|
496
|
-
});
|
|
497
|
-
this.name = "FetchError";
|
|
498
|
-
this.status = opts.status;
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
var ToolValidationError = class extends WrongStackError {
|
|
502
|
-
constructor(opts) {
|
|
503
|
-
super({
|
|
504
|
-
message: opts.message,
|
|
505
|
-
code: ERROR_CODES.VALIDATION_ERROR,
|
|
506
|
-
subsystem: "general",
|
|
507
|
-
severity: "error",
|
|
508
|
-
recoverable: false,
|
|
509
|
-
context: { field: opts.field, ...opts.context },
|
|
510
|
-
cause: opts.cause
|
|
511
|
-
});
|
|
512
|
-
this.name = "ToolValidationError";
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
var ParseError = class extends WrongStackError {
|
|
516
|
-
source;
|
|
517
|
-
constructor(opts) {
|
|
518
|
-
super({
|
|
519
|
-
message: opts.message,
|
|
520
|
-
code: ERROR_CODES.PARSE_FAILED,
|
|
521
|
-
subsystem: "general",
|
|
522
|
-
severity: "error",
|
|
523
|
-
recoverable: false,
|
|
524
|
-
context: { source: opts.source, ...opts.context },
|
|
525
|
-
cause: opts.cause
|
|
526
|
-
});
|
|
527
|
-
this.name = "ParseError";
|
|
528
|
-
this.source = opts.source;
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
function isWrongStackError(err) {
|
|
532
|
-
return err instanceof WrongStackError;
|
|
533
|
-
}
|
|
534
|
-
function isToolError(err) {
|
|
535
|
-
return err instanceof ToolError;
|
|
536
|
-
}
|
|
537
|
-
function isConfigError(err) {
|
|
538
|
-
return err instanceof ConfigError;
|
|
539
|
-
}
|
|
540
|
-
function isPluginError(err) {
|
|
541
|
-
return err instanceof PluginError;
|
|
542
|
-
}
|
|
543
|
-
function isSessionError(err) {
|
|
544
|
-
return err instanceof SessionError;
|
|
545
|
-
}
|
|
546
|
-
function isAgentError(err) {
|
|
547
|
-
return err instanceof AgentError;
|
|
548
|
-
}
|
|
549
|
-
function isFsError(err) {
|
|
550
|
-
return err instanceof FsError;
|
|
551
|
-
}
|
|
552
|
-
function isToolValidationError(err) {
|
|
553
|
-
return err instanceof ToolValidationError;
|
|
554
|
-
}
|
|
555
|
-
function isFetchError(err) {
|
|
556
|
-
return err instanceof FetchError;
|
|
557
|
-
}
|
|
558
|
-
function isParseError(err) {
|
|
559
|
-
return err instanceof ParseError;
|
|
560
|
-
}
|
|
561
|
-
function isSddError(err) {
|
|
562
|
-
return err instanceof SddError;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// src/types/memory.ts
|
|
566
|
-
var MEMORY_TYPE_LABELS = {
|
|
567
|
-
fact: "Fact",
|
|
568
|
-
decision: "Decision",
|
|
569
|
-
convention: "Convention",
|
|
570
|
-
preference: "Preference",
|
|
571
|
-
reference: "Reference",
|
|
572
|
-
anti_pattern: "Anti-pattern"
|
|
573
|
-
};
|
|
574
|
-
function defineMemoryCapability(id) {
|
|
575
|
-
return Object.freeze({
|
|
576
|
-
id,
|
|
577
|
-
/** Identity function that makes the brand a real runtime value so
|
|
578
|
-
* `defineMemoryCapability<A>('x')` and `defineMemoryCapability<B>('x')`
|
|
579
|
-
* produce structurally distinct objects. Capability lookup is still
|
|
580
|
-
* keyed by `id` only — the brand prevents accidental cross-type casts
|
|
581
|
-
* at the type level. */
|
|
582
|
-
__memoryCapabilityType: (v) => v
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// src/types/mode-prompts.ts
|
|
587
|
-
import { readFileSync, statSync } from "node:fs";
|
|
588
|
-
import * as path from "node:path";
|
|
589
|
-
import { fileURLToPath } from "node:url";
|
|
590
|
-
function modePrompt(id) {
|
|
591
|
-
for (const dir of modePromptDirCandidates()) {
|
|
592
|
-
try {
|
|
593
|
-
return readFileSync(path.join(dir, `${id}.md`), "utf8").trimEnd();
|
|
594
|
-
} catch {
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
return "";
|
|
598
|
-
}
|
|
599
|
-
function modePromptDirCandidates() {
|
|
600
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
601
|
-
const candidates = [
|
|
602
|
-
path.resolve(here, "../../instructions/modes"),
|
|
603
|
-
path.resolve(here, "../instructions/modes"),
|
|
604
|
-
path.resolve(here, "instructions/modes")
|
|
605
|
-
];
|
|
606
|
-
return candidates.sort((a, b) => Number(!isDirectory(a)) - Number(!isDirectory(b)));
|
|
607
|
-
}
|
|
608
|
-
function isDirectory(candidate) {
|
|
609
|
-
try {
|
|
610
|
-
return statSync(candidate).isDirectory();
|
|
611
|
-
} catch {
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
// src/types/mode.ts
|
|
617
|
-
var DEFAULT_MODES = [
|
|
618
|
-
{
|
|
619
|
-
id: "default",
|
|
620
|
-
name: "Default",
|
|
621
|
-
description: "Balanced general-purpose mode; use when no special token/coverage trade-off is needed",
|
|
622
|
-
prompt: "",
|
|
623
|
-
tags: ["general", "balanced"]
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
id: "brief",
|
|
627
|
-
name: "Brief",
|
|
628
|
-
description: "Ultra-compact responses for low-context, high-speed work",
|
|
629
|
-
prompt: modePrompt("brief"),
|
|
630
|
-
tags: ["lite", "fast", "concise", "token-saving"],
|
|
631
|
-
toolPreferences: ["read", "edit", "bash"],
|
|
632
|
-
suggestedSkills: []
|
|
633
|
-
},
|
|
634
|
-
{
|
|
635
|
-
id: "review-lite",
|
|
636
|
-
name: "Review Lite",
|
|
637
|
-
description: "Token-saving code review: changed files only, top correctness/security risks",
|
|
638
|
-
prompt: modePrompt("review-lite"),
|
|
639
|
-
tags: ["lite", "review", "quality", "token-saving"],
|
|
640
|
-
toolPreferences: ["git", "diff", "read", "grep"],
|
|
641
|
-
suggestedSkills: ["bug-hunter", "typescript-strict"]
|
|
642
|
-
},
|
|
643
|
-
{
|
|
644
|
-
id: "audit-lite",
|
|
645
|
-
name: "Audit Lite",
|
|
646
|
-
description: "Token-saving security triage for a small diff or named file",
|
|
647
|
-
prompt: modePrompt("audit-lite"),
|
|
648
|
-
tags: ["lite", "security", "audit", "token-saving"],
|
|
649
|
-
toolPreferences: ["grep", "read", "git"],
|
|
650
|
-
suggestedSkills: ["security-scanner"]
|
|
651
|
-
},
|
|
652
|
-
{
|
|
653
|
-
id: "plan-lite",
|
|
654
|
-
name: "Plan Lite",
|
|
655
|
-
description: "Token-saving planning: 3-6 actionable steps, minimal design debate",
|
|
656
|
-
prompt: modePrompt("plan-lite"),
|
|
657
|
-
tags: ["lite", "planning", "architecture", "token-saving"],
|
|
658
|
-
toolPreferences: ["tree", "glob", "read", "grep"],
|
|
659
|
-
suggestedSkills: ["refactor-planner"]
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
id: "debug-lite",
|
|
663
|
-
name: "Debug Lite",
|
|
664
|
-
description: "Token-saving bug triage: one hypothesis, nearest evidence, narrow check",
|
|
665
|
-
prompt: modePrompt("debug-lite"),
|
|
666
|
-
tags: ["lite", "debug", "triage", "token-saving"],
|
|
667
|
-
toolPreferences: ["read", "grep", "test", "logs"],
|
|
668
|
-
suggestedSkills: ["bug-hunter"]
|
|
669
|
-
},
|
|
670
|
-
{
|
|
671
|
-
id: "test-lite",
|
|
672
|
-
name: "Test Lite",
|
|
673
|
-
description: "Token-saving tests: one focused regression or narrow verification target",
|
|
674
|
-
prompt: modePrompt("test-lite"),
|
|
675
|
-
tags: ["lite", "testing", "qa", "token-saving"],
|
|
676
|
-
toolPreferences: ["test", "read", "grep"],
|
|
677
|
-
suggestedSkills: ["testing"]
|
|
678
|
-
},
|
|
679
|
-
{
|
|
680
|
-
id: "refactor-lite",
|
|
681
|
-
name: "Refactor Lite",
|
|
682
|
-
description: "Token-saving cleanup: small scoped behavior-preserving changes",
|
|
683
|
-
prompt: modePrompt("refactor-lite"),
|
|
684
|
-
tags: ["lite", "refactor", "token-saving"],
|
|
685
|
-
toolPreferences: ["read", "edit", "test"],
|
|
686
|
-
suggestedSkills: ["typescript-strict"]
|
|
687
|
-
},
|
|
688
|
-
{
|
|
689
|
-
id: "research-lite",
|
|
690
|
-
name: "Research Lite",
|
|
691
|
-
description: "Token-saving web research: one search, one authoritative fetch, short answer",
|
|
692
|
-
prompt: modePrompt("research-lite"),
|
|
693
|
-
tags: ["lite", "research", "web", "token-saving"],
|
|
694
|
-
toolPreferences: ["search", "fetch"],
|
|
695
|
-
suggestedSkills: ["research-web"]
|
|
696
|
-
},
|
|
697
|
-
{
|
|
698
|
-
id: "code-reviewer",
|
|
699
|
-
name: "Review Deep",
|
|
700
|
-
description: "Comprehensive code review across contracts, edge cases, lifecycle, errors, concurrency",
|
|
701
|
-
prompt: modePrompt("code-reviewer"),
|
|
702
|
-
tags: ["deep", "review", "quality", "security"],
|
|
703
|
-
toolPreferences: ["read", "grep", "git", "diff", "test"],
|
|
704
|
-
suggestedSkills: ["bug-hunter", "security-scanner", "typescript-strict", "testing"]
|
|
705
|
-
},
|
|
706
|
-
{
|
|
707
|
-
id: "code-auditor",
|
|
708
|
-
name: "Audit Deep",
|
|
709
|
-
description: "Comprehensive security audit with category coverage and exploitability notes",
|
|
710
|
-
prompt: modePrompt("code-auditor"),
|
|
711
|
-
tags: ["deep", "security", "audit", "compliance"],
|
|
712
|
-
toolPreferences: ["grep", "read", "audit", "bash"],
|
|
713
|
-
suggestedSkills: ["security-scanner", "bug-hunter", "audit-log"]
|
|
714
|
-
},
|
|
715
|
-
{
|
|
716
|
-
id: "architect",
|
|
717
|
-
name: "Architecture Deep",
|
|
718
|
-
description: "Comprehensive architecture and cross-module contract analysis",
|
|
719
|
-
prompt: modePrompt("architect"),
|
|
720
|
-
tags: ["deep", "architecture", "design", "scalability"],
|
|
721
|
-
toolPreferences: ["read", "glob", "tree", "diff"],
|
|
722
|
-
suggestedSkills: ["api-design", "refactor-planner", "node-modern", "docker-deploy"]
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
id: "debugger",
|
|
726
|
-
name: "Debug Deep",
|
|
727
|
-
description: "Comprehensive root-cause analysis with traces, logs, assumptions, and verification",
|
|
728
|
-
prompt: modePrompt("debugger"),
|
|
729
|
-
tags: ["deep", "debug", "investigation", "error-resolution"],
|
|
730
|
-
toolPreferences: ["read", "grep", "bash", "logs", "test"],
|
|
731
|
-
suggestedSkills: ["bug-hunter", "audit-log", "observability"]
|
|
732
|
-
},
|
|
733
|
-
{
|
|
734
|
-
id: "tester",
|
|
735
|
-
name: "Test Deep",
|
|
736
|
-
description: "Comprehensive QA mode for coverage, boundaries, isolation, and integration gaps",
|
|
737
|
-
prompt: modePrompt("tester"),
|
|
738
|
-
tags: ["deep", "testing", "qa", "quality"],
|
|
739
|
-
toolPreferences: ["read", "grep", "test", "bash"],
|
|
740
|
-
suggestedSkills: ["testing", "bug-hunter", "typescript-strict"]
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
id: "devops",
|
|
744
|
-
name: "DevOps Deep",
|
|
745
|
-
description: "Comprehensive infrastructure, deployment, observability, and operations review",
|
|
746
|
-
prompt: modePrompt("devops"),
|
|
747
|
-
tags: ["deep", "devops", "infrastructure", "operations"],
|
|
748
|
-
toolPreferences: ["read", "bash", "grep", "logs", "git"],
|
|
749
|
-
suggestedSkills: ["docker-deploy", "observability", "security-scanner"]
|
|
750
|
-
},
|
|
751
|
-
{
|
|
752
|
-
id: "refactorer",
|
|
753
|
-
name: "Refactor Deep",
|
|
754
|
-
description: "Comprehensive modernization/refactor mode with contracts and verification discipline",
|
|
755
|
-
prompt: modePrompt("refactorer"),
|
|
756
|
-
tags: ["deep", "refactor", "modernization", "improvement"],
|
|
757
|
-
toolPreferences: ["read", "edit", "test", "git", "grep"],
|
|
758
|
-
suggestedSkills: ["refactor-planner", "typescript-strict", "node-modern", "testing"]
|
|
759
|
-
},
|
|
760
|
-
{
|
|
761
|
-
id: "ui-design",
|
|
762
|
-
name: "UI Design Deep",
|
|
763
|
-
description: "Comprehensive design-first frontend/mobile UI work with kit, tokens, and accessibility",
|
|
764
|
-
prompt: modePrompt("ui-design"),
|
|
765
|
-
tags: ["deep", "ui", "frontend", "mobile", "design"],
|
|
766
|
-
toolPreferences: ["design", "write", "edit", "read", "scaffold"],
|
|
767
|
-
suggestedSkills: ["react-modern"]
|
|
768
|
-
},
|
|
769
|
-
{
|
|
770
|
-
id: "teach",
|
|
771
|
-
name: "Teach Deep",
|
|
772
|
-
description: "Mentor mode with explanations, mental models, trade-offs, and takeaways",
|
|
773
|
-
prompt: modePrompt("teach"),
|
|
774
|
-
tags: ["deep", "teaching", "mentor", "learning"],
|
|
775
|
-
toolPreferences: ["read", "edit", "explain"],
|
|
776
|
-
suggestedSkills: ["prompt-engineering", "skill-creator", "node-modern", "typescript-strict"]
|
|
777
|
-
},
|
|
778
|
-
{
|
|
779
|
-
id: "research-web",
|
|
780
|
-
name: "Research Deep",
|
|
781
|
-
description: "Comprehensive current-data research with cross-checking and reusable findings",
|
|
782
|
-
prompt: modePrompt("research-web"),
|
|
783
|
-
tags: ["deep", "research", "web", "current-data", "up-to-date"],
|
|
784
|
-
toolPreferences: ["search", "fetch", "context_manager"],
|
|
785
|
-
suggestedSkills: ["research-web", "tech-stack", "node-modern", "security-scanner", "react-modern"]
|
|
786
|
-
}
|
|
787
|
-
];
|
|
788
|
-
|
|
789
|
-
// src/types/prompt.ts
|
|
790
|
-
var BUILTIN_PROMPT_CATEGORIES = [
|
|
791
|
-
"coding",
|
|
792
|
-
"debugging",
|
|
793
|
-
"refactoring",
|
|
794
|
-
"testing",
|
|
795
|
-
"code-review",
|
|
796
|
-
"architecture",
|
|
797
|
-
"devops",
|
|
798
|
-
"documentation",
|
|
799
|
-
"data-analysis",
|
|
800
|
-
"writing",
|
|
801
|
-
"research",
|
|
802
|
-
"product",
|
|
803
|
-
"agentic-workflows",
|
|
804
|
-
"meta-prompting",
|
|
805
|
-
"uncategorized"
|
|
806
|
-
];
|
|
807
|
-
var PROMPT_CATEGORY_LABELS = {
|
|
808
|
-
coding: "Coding",
|
|
809
|
-
debugging: "Debugging",
|
|
810
|
-
refactoring: "Refactoring",
|
|
811
|
-
testing: "Testing",
|
|
812
|
-
"code-review": "Code Review",
|
|
813
|
-
architecture: "Architecture",
|
|
814
|
-
devops: "DevOps",
|
|
815
|
-
documentation: "Documentation",
|
|
816
|
-
"data-analysis": "Data Analysis",
|
|
817
|
-
writing: "Writing",
|
|
818
|
-
research: "Research",
|
|
819
|
-
product: "Product",
|
|
820
|
-
"agentic-workflows": "Agentic Workflows",
|
|
821
|
-
"meta-prompting": "Meta-Prompting",
|
|
822
|
-
uncategorized: "Uncategorized"
|
|
823
|
-
};
|
|
824
|
-
function isBuiltinCategory(value) {
|
|
825
|
-
return BUILTIN_PROMPT_CATEGORIES.includes(value);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
// src/types/prompt-registry.ts
|
|
829
|
-
var SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
830
|
-
var CHECKSUM_RE = /^[a-f0-9]{64}$/;
|
|
831
|
-
var MAX_STR = 4096;
|
|
832
|
-
function validateRegistryManifest(raw) {
|
|
833
|
-
const errors = [];
|
|
834
|
-
if (!raw || typeof raw !== "object") return { ok: false, errors: ["manifest is not an object"] };
|
|
835
|
-
const m = raw;
|
|
836
|
-
if (m["registryVersion"] !== 1) errors.push("registryVersion must be 1");
|
|
837
|
-
if (typeof m["source"] !== "string" || !m["source"])
|
|
838
|
-
errors.push("source must be a non-empty string");
|
|
839
|
-
if (typeof m["generatedAt"] !== "string") errors.push("generatedAt must be a string");
|
|
840
|
-
if (!Array.isArray(m["prompts"])) {
|
|
841
|
-
errors.push("prompts must be an array");
|
|
842
|
-
return { ok: false, errors };
|
|
843
|
-
}
|
|
844
|
-
const seen = /* @__PURE__ */ new Set();
|
|
845
|
-
const refs = [];
|
|
846
|
-
m["prompts"].forEach((p, i) => {
|
|
847
|
-
if (!p || typeof p !== "object") {
|
|
848
|
-
errors.push(`prompts[${i}] is not an object`);
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
const r = p;
|
|
852
|
-
const slug = r["slug"];
|
|
853
|
-
if (typeof slug !== "string" || !SLUG_RE.test(slug)) {
|
|
854
|
-
errors.push(`prompts[${i}].slug invalid (must be kebab-case)`);
|
|
855
|
-
return;
|
|
856
|
-
}
|
|
857
|
-
if (seen.has(slug)) {
|
|
858
|
-
errors.push(`prompts[${i}].slug "${slug}" duplicated`);
|
|
859
|
-
return;
|
|
860
|
-
}
|
|
861
|
-
seen.add(slug);
|
|
862
|
-
if (typeof r["checksum"] !== "string" || !CHECKSUM_RE.test(r["checksum"])) {
|
|
863
|
-
errors.push(`prompts[${i}].checksum must be a 64-char sha256 hex`);
|
|
864
|
-
return;
|
|
865
|
-
}
|
|
866
|
-
for (const field of ["id", "title", "description", "category"]) {
|
|
867
|
-
const v = r[field];
|
|
868
|
-
if (typeof v !== "string" || v.length === 0 || v.length > MAX_STR) {
|
|
869
|
-
errors.push(`prompts[${i}].${field} must be a non-empty string under ${MAX_STR} chars`);
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
const tags = Array.isArray(r["tags"]) ? r["tags"].filter((t) => typeof t === "string") : [];
|
|
874
|
-
refs.push({
|
|
875
|
-
id: r["id"],
|
|
876
|
-
slug,
|
|
877
|
-
title: r["title"],
|
|
878
|
-
description: r["description"],
|
|
879
|
-
category: r["category"],
|
|
880
|
-
tags,
|
|
881
|
-
checksum: r["checksum"],
|
|
882
|
-
version: typeof r["version"] === "string" ? r["version"] : void 0,
|
|
883
|
-
license: typeof r["license"] === "string" ? r["license"] : void 0,
|
|
884
|
-
url: typeof r["url"] === "string" ? r["url"] : void 0
|
|
885
|
-
});
|
|
886
|
-
});
|
|
887
|
-
if (errors.length > 0) return { ok: false, errors };
|
|
888
|
-
return {
|
|
889
|
-
ok: true,
|
|
890
|
-
manifest: {
|
|
891
|
-
registryVersion: 1,
|
|
892
|
-
source: m["source"],
|
|
893
|
-
generatedAt: m["generatedAt"],
|
|
894
|
-
prompts: refs
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
}
|
|
898
|
-
function diffRegistry(local, manifest) {
|
|
899
|
-
const localBySlug = new Map(local.map((e) => [e.slug, e.checksum]));
|
|
900
|
-
const diff = { added: [], updated: [], unchanged: [] };
|
|
901
|
-
for (const ref of manifest.prompts) {
|
|
902
|
-
if (!localBySlug.has(ref.slug)) diff.added.push(ref);
|
|
903
|
-
else if (localBySlug.get(ref.slug) !== ref.checksum) diff.updated.push(ref);
|
|
904
|
-
else diff.unchanged.push(ref);
|
|
905
|
-
}
|
|
906
|
-
return diff;
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
// src/utils/string.ts
|
|
910
|
-
function truncate(s, max) {
|
|
911
|
-
return s.length <= max ? s : `${s.slice(0, max - 1)}\u2026`;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
// src/types/quota-regex.ts
|
|
915
|
-
var QUOTA_EXHAUSTED_RE = /(?:insufficient|exhausted|depleted|exceeded|no|not enough)[-_\s]*(?:quota|credit|balance)|(?:quota|credit|balance)(?:\s+(?:has|have))?(?:\s+been)?[-_\s]*(?:exhausted|depleted|exceeded|insufficient)|billing[_\s-]*(?:hard[_\s-]*)?limit|payment required|spending limit|plan limit|(?:usage|credit)[-_\s]*(?:quota|limit)(?![-_\w])|usage[-_\s]*(?:limit|quota)[-_\s]*(?:reached|exceeded|for)/i;
|
|
916
|
-
|
|
917
|
-
// src/types/provider.ts
|
|
918
|
-
var REASONING_EFFORT_LEVELS = [
|
|
919
|
-
"none",
|
|
920
|
-
"minimal",
|
|
921
|
-
"low",
|
|
922
|
-
"medium",
|
|
923
|
-
"high",
|
|
924
|
-
"xhigh",
|
|
925
|
-
"max"
|
|
926
|
-
];
|
|
927
|
-
function isReasoningEffort(value) {
|
|
928
|
-
return typeof value === "string" && REASONING_EFFORT_LEVELS.includes(value);
|
|
929
|
-
}
|
|
930
|
-
function effectiveInputTokens(usage) {
|
|
931
|
-
return usage.input + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
|
|
932
|
-
}
|
|
933
|
-
function freshInputTokens(usage) {
|
|
934
|
-
return Math.max(0, effectiveInputTokens(usage) - (usage.cacheRead ?? 0));
|
|
935
|
-
}
|
|
936
|
-
function promptCacheHitRatio(usage) {
|
|
937
|
-
const total = effectiveInputTokens(usage);
|
|
938
|
-
if (!Number.isFinite(total) || total <= 0) return 0;
|
|
939
|
-
const cached = Number.isFinite(usage.cacheRead) ? Math.max(0, usage.cacheRead ?? 0) : 0;
|
|
940
|
-
return Math.min(1, cached / total);
|
|
941
|
-
}
|
|
942
|
-
var CONTEXT_OVERFLOW_RE = /context.length|context.window|maximum context|max.*tokens?.*exceeded|(?:prompt|request|input|messages?).{0,12}too (?:large|long)|exceeds the context|\btokens\b.*exceed|too many tokens|reduce the length|resulted in \d+ tokens|context_length_exceeded/i;
|
|
943
|
-
var CONTENT_FILTER_RE = /content.(filter|policy|moderation)|safety (system|filter)/i;
|
|
944
|
-
var RATE_LIMIT_EXCEEDED_RE = /rate[-_\s]*limit[-_\s]*exceeded/i;
|
|
945
|
-
function classifyProviderError(status, body, message) {
|
|
946
|
-
const type = body?.type;
|
|
947
|
-
const text = [message, body?.message, type, body?.raw].filter(Boolean).join("\n");
|
|
948
|
-
if (status === 0) return "network";
|
|
949
|
-
if (status === 408) return "timeout";
|
|
950
|
-
if (status === 599) return "stream_hang";
|
|
951
|
-
if (QUOTA_EXHAUSTED_RE.test(text)) return "quota_exhausted";
|
|
952
|
-
if (status === 402) return "quota_exhausted";
|
|
953
|
-
if (status === 429 && body?.message && body.type !== "rate_limit_exceeded" && RATE_LIMIT_EXCEEDED_RE.test(body.message)) {
|
|
954
|
-
return "quota_exhausted";
|
|
955
|
-
}
|
|
956
|
-
if (type === "rate_limit_error" || status === 429) return "rate_limit";
|
|
957
|
-
if (type === "overloaded_error" || status === 529) return "overloaded";
|
|
958
|
-
if (status >= 500) return "server";
|
|
959
|
-
if (type === "authentication_error" || type === "permission_error" || status === 401 || status === 403) {
|
|
960
|
-
return "auth";
|
|
961
|
-
}
|
|
962
|
-
if (type === "content_filter" || CONTENT_FILTER_RE.test(text)) return "content_filter";
|
|
963
|
-
if (status === 413 || status >= 400 && CONTEXT_OVERFLOW_RE.test(text)) {
|
|
964
|
-
return "context_overflow";
|
|
965
|
-
}
|
|
966
|
-
if (status >= 400) return "invalid_request";
|
|
967
|
-
return "unknown";
|
|
968
|
-
}
|
|
969
|
-
var MAX_RESET_HINT_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
970
|
-
function isRetryableKind(kind) {
|
|
971
|
-
return RETRYABLE_BY_KIND[kind];
|
|
972
|
-
}
|
|
973
|
-
var RETRYABLE_BY_KIND = {
|
|
974
|
-
rate_limit: true,
|
|
975
|
-
quota_exhausted: false,
|
|
976
|
-
overloaded: true,
|
|
977
|
-
server: true,
|
|
978
|
-
timeout: true,
|
|
979
|
-
network: true,
|
|
980
|
-
stream_hang: true,
|
|
981
|
-
auth: false,
|
|
982
|
-
context_overflow: false,
|
|
983
|
-
content_filter: false,
|
|
984
|
-
invalid_request: false,
|
|
985
|
-
unknown: false
|
|
986
|
-
};
|
|
987
|
-
function isFallbackWorthy(kind) {
|
|
988
|
-
return FALLBACK_WORTHY_BY_KIND[kind];
|
|
989
|
-
}
|
|
990
|
-
var FALLBACK_WORTHY_BY_KIND = {
|
|
991
|
-
rate_limit: true,
|
|
992
|
-
quota_exhausted: true,
|
|
993
|
-
overloaded: true,
|
|
994
|
-
server: true,
|
|
995
|
-
timeout: true,
|
|
996
|
-
network: true,
|
|
997
|
-
stream_hang: true,
|
|
998
|
-
auth: false,
|
|
999
|
-
context_overflow: false,
|
|
1000
|
-
content_filter: false,
|
|
1001
|
-
invalid_request: false,
|
|
1002
|
-
unknown: false
|
|
1003
|
-
};
|
|
1004
|
-
var ProviderError = class extends WrongStackError {
|
|
1005
|
-
status;
|
|
1006
|
-
retryable;
|
|
1007
|
-
providerId;
|
|
1008
|
-
/** Canonical failure classification — see {@link ProviderErrorKind}. */
|
|
1009
|
-
kind;
|
|
1010
|
-
body;
|
|
1011
|
-
/**
|
|
1012
|
-
* Duck-type guard: checks whether an unknown value *looks like* a
|
|
1013
|
-
* ProviderError by probing for its structural properties. Use this
|
|
1014
|
-
* anywhere the constructor identity might cross a package boundary
|
|
1015
|
-
* (e.g. `@wrongstack/providers` creates the error, but the runner in
|
|
1016
|
-
* `@wrongstack/core` checks it). A plain `instanceof ProviderError`
|
|
1017
|
-
* can fail when npm hoists duplicate copies of `@wrongstack/core`,
|
|
1018
|
-
* each with its own class identity.
|
|
1019
|
-
*
|
|
1020
|
-
* The check tests for the four invariant properties defined in the
|
|
1021
|
-
* constructor: `name === 'ProviderError'`, `status` (number),
|
|
1022
|
-
* `retryable` (boolean), and `kind` (string). This tolerates both
|
|
1023
|
-
* true `ProviderError` instances and cross-boundary copies.
|
|
1024
|
-
*/
|
|
1025
|
-
static isProviderError(err) {
|
|
1026
|
-
if (!err || typeof err !== "object") return false;
|
|
1027
|
-
const e = err;
|
|
1028
|
-
const name = e.name;
|
|
1029
|
-
if (typeof name !== "string" || !name.endsWith("Error")) return false;
|
|
1030
|
-
return typeof e.status === "number" && typeof e.retryable === "boolean" && typeof e.kind === "string" && typeof e.describe === "function";
|
|
1031
|
-
}
|
|
1032
|
-
constructor(message, status, retryable, providerId, opts = {}) {
|
|
1033
|
-
const kind = opts.kind ?? classifyProviderError(status, opts.body, message);
|
|
1034
|
-
super({
|
|
1035
|
-
message,
|
|
1036
|
-
code: kindToCode(kind),
|
|
1037
|
-
subsystem: "provider",
|
|
1038
|
-
severity: status >= 500 ? "error" : "warning",
|
|
1039
|
-
recoverable: retryable,
|
|
1040
|
-
context: { providerId, status },
|
|
1041
|
-
cause: opts.cause
|
|
1042
|
-
});
|
|
1043
|
-
this.name = "ProviderError";
|
|
1044
|
-
this.status = status;
|
|
1045
|
-
this.retryable = retryable;
|
|
1046
|
-
this.providerId = providerId;
|
|
1047
|
-
this.kind = kind;
|
|
1048
|
-
this.body = opts.body;
|
|
1049
|
-
}
|
|
1050
|
-
/**
|
|
1051
|
-
* Render a one-line, user-facing description. Designed for the CLI/TUI
|
|
1052
|
-
* status line and the agent's retry warning. Avoids dumping raw JSON
|
|
1053
|
-
* (which is what users see today when a 529 lands and the log message
|
|
1054
|
-
* includes the full `{"type":"error",...}` body).
|
|
1055
|
-
*
|
|
1056
|
-
* Examples:
|
|
1057
|
-
* "minimax-coding-plan overloaded (529): High traffic detected. Upgrade for highspeed model. [req 06534785201de9c0…]"
|
|
1058
|
-
* "openai rate limited (429): Retry after 12s"
|
|
1059
|
-
* "anthropic invalid request (400): messages.0.role must be one of 'user'|'assistant'"
|
|
1060
|
-
* "groq HTTP 500 (server error)"
|
|
1061
|
-
*/
|
|
1062
|
-
describe() {
|
|
1063
|
-
const kind = describeStatus(this.status, this.body?.type);
|
|
1064
|
-
const head = `${this.providerId} ${kind}`;
|
|
1065
|
-
const detail = this.body?.message?.trim();
|
|
1066
|
-
const reqId = this.body?.requestId ? ` [req ${this.body.requestId.slice(0, 16)}${this.body.requestId.length > 16 ? "\u2026" : ""}]` : "";
|
|
1067
|
-
if (detail && detail.length > 0) {
|
|
1068
|
-
return `${head}: ${truncate(detail, 240)}${reqId}`;
|
|
1069
|
-
}
|
|
1070
|
-
return `${head}${reqId}`;
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1073
|
-
function isContextOverflowShaped(err) {
|
|
1074
|
-
if (!(err instanceof ProviderError) && !ProviderError.isProviderError(err)) return false;
|
|
1075
|
-
const providerErr = err;
|
|
1076
|
-
if (providerErr.kind === "context_overflow" || providerErr.status === 413) return true;
|
|
1077
|
-
if (providerErr.status < 400) return false;
|
|
1078
|
-
const text = [
|
|
1079
|
-
providerErr.message,
|
|
1080
|
-
providerErr.body?.message,
|
|
1081
|
-
providerErr.body?.type,
|
|
1082
|
-
providerErr.body?.raw
|
|
1083
|
-
].filter(Boolean).join("\n");
|
|
1084
|
-
return CONTEXT_OVERFLOW_RE.test(text);
|
|
1085
|
-
}
|
|
1086
|
-
function describeStatus(status, type) {
|
|
1087
|
-
if (status === 0) return "network error";
|
|
1088
|
-
if (status === 599) return `stream hang (${status})`;
|
|
1089
|
-
if (type === "overloaded_error" || status === 529) return `overloaded (${status})`;
|
|
1090
|
-
if (type === "rate_limit_error" || status === 429) return `rate limited (${status})`;
|
|
1091
|
-
if (type === "authentication_error" || status === 401) return `auth failed (${status})`;
|
|
1092
|
-
if (type === "permission_error" || status === 403) return `forbidden (${status})`;
|
|
1093
|
-
if (type === "not_found_error" || status === 404) return `not found (${status})`;
|
|
1094
|
-
if (type === "content_filter") return `content filtered (${status})`;
|
|
1095
|
-
if (type === "invalid_request_error" || status === 400) return `invalid request (${status})`;
|
|
1096
|
-
if (status === 408) return `timeout (${status})`;
|
|
1097
|
-
if (status >= 500 && status < 600) return `HTTP ${status} (server error)`;
|
|
1098
|
-
if (type) return `${type} (${status})`;
|
|
1099
|
-
return `HTTP ${status}`;
|
|
1100
|
-
}
|
|
1101
|
-
var StreamHangError = class extends ProviderError {
|
|
1102
|
-
/** Name of the provider that hung, e.g. "zai", "anthropic". */
|
|
1103
|
-
hungProviderId;
|
|
1104
|
-
/** Model that was being called when the hang occurred. */
|
|
1105
|
-
hungModel;
|
|
1106
|
-
/** How long (ms) we waited for the next chunk before declaring a hang. */
|
|
1107
|
-
hangTimeoutMs;
|
|
1108
|
-
/** How many bytes were received before the hang. */
|
|
1109
|
-
bytesReceived;
|
|
1110
|
-
/** Elapsed time (ms) from the start of the stream until the hang. */
|
|
1111
|
-
elapsedMs;
|
|
1112
|
-
constructor(opts) {
|
|
1113
|
-
super(
|
|
1114
|
-
`Stream hang: ${opts.providerId}/${opts.model} \u2014 no data for ${opts.hangTimeoutMs}ms after ${opts.bytesReceived} bytes (${opts.elapsedMs}ms elapsed)`,
|
|
1115
|
-
599,
|
|
1116
|
-
true,
|
|
1117
|
-
// always retryable
|
|
1118
|
-
opts.providerId,
|
|
1119
|
-
{
|
|
1120
|
-
body: {
|
|
1121
|
-
message: `Stream stalled after ${opts.elapsedMs}ms, ${opts.bytesReceived} bytes received`
|
|
1122
|
-
},
|
|
1123
|
-
cause: opts.cause
|
|
1124
|
-
}
|
|
1125
|
-
);
|
|
1126
|
-
this.name = "StreamHangError";
|
|
1127
|
-
this.hungProviderId = opts.providerId;
|
|
1128
|
-
this.hungModel = opts.model;
|
|
1129
|
-
this.hangTimeoutMs = opts.hangTimeoutMs;
|
|
1130
|
-
this.bytesReceived = opts.bytesReceived;
|
|
1131
|
-
this.elapsedMs = opts.elapsedMs;
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
var KIND_TO_CODE = {
|
|
1135
|
-
network: ERROR_CODES.PROVIDER_NETWORK_ERROR,
|
|
1136
|
-
timeout: ERROR_CODES.PROVIDER_NETWORK_ERROR,
|
|
1137
|
-
rate_limit: ERROR_CODES.PROVIDER_RATE_LIMITED,
|
|
1138
|
-
quota_exhausted: ERROR_CODES.PROVIDER_RATE_LIMITED,
|
|
1139
|
-
auth: ERROR_CODES.PROVIDER_AUTH_FAILED,
|
|
1140
|
-
overloaded: ERROR_CODES.PROVIDER_OVERLOADED,
|
|
1141
|
-
context_overflow: ERROR_CODES.PROVIDER_CONTEXT_OVERFLOW,
|
|
1142
|
-
server: ERROR_CODES.PROVIDER_SERVER_ERROR,
|
|
1143
|
-
stream_hang: ERROR_CODES.PROVIDER_SERVER_ERROR,
|
|
1144
|
-
content_filter: ERROR_CODES.PROVIDER_INVALID_REQUEST,
|
|
1145
|
-
invalid_request: ERROR_CODES.PROVIDER_INVALID_REQUEST,
|
|
1146
|
-
unknown: ERROR_CODES.PROVIDER_INVALID_REQUEST
|
|
1147
|
-
};
|
|
1148
|
-
function kindToCode(kind) {
|
|
1149
|
-
return KIND_TO_CODE[kind];
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
// src/types/session-markers.ts
|
|
1153
|
-
var SESSION_MARKER_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
1154
|
-
"mode_changed",
|
|
1155
|
-
"compaction",
|
|
1156
|
-
"checkpoint",
|
|
1157
|
-
"skill_activated",
|
|
1158
|
-
"skill_deactivated",
|
|
1159
|
-
"agent_spawned",
|
|
1160
|
-
"agent_stopped",
|
|
1161
|
-
"agent_error",
|
|
1162
|
-
"error",
|
|
1163
|
-
"provider_retry",
|
|
1164
|
-
"provider_error",
|
|
1165
|
-
"message_truncated"
|
|
1166
|
-
]);
|
|
1167
|
-
var CHAT_MARKER_SOURCES = new Set(
|
|
1168
|
-
[...SESSION_MARKER_EVENT_TYPES].filter((type) => type !== "checkpoint")
|
|
1169
|
-
);
|
|
1170
|
-
function sessionEventToMarker(ev) {
|
|
1171
|
-
switch (ev.type) {
|
|
1172
|
-
case "compaction": {
|
|
1173
|
-
const before = (ev.before / 1e3).toFixed(0);
|
|
1174
|
-
const after = (ev.after / 1e3).toFixed(0);
|
|
1175
|
-
const level = ev.level ? ` (${ev.level})` : "";
|
|
1176
|
-
const reductions = ev.reductions && ev.reductions.length > 0 ? ` [${ev.reductions.map((r) => `${r.phase}: \u2212${r.saved}`).join(", ")}]` : "";
|
|
1177
|
-
return {
|
|
1178
|
-
ts: ev.ts,
|
|
1179
|
-
source: ev.type,
|
|
1180
|
-
level: "info",
|
|
1181
|
-
text: `\u27F2 context compacted${level}: ${before}K \u2192 ${after}K tokens${reductions}`
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
case "error":
|
|
1185
|
-
return {
|
|
1186
|
-
ts: ev.ts,
|
|
1187
|
-
source: ev.type,
|
|
1188
|
-
level: "error",
|
|
1189
|
-
text: ev.phase ? `[${ev.phase}] ${ev.message}` : ev.message
|
|
1190
|
-
};
|
|
1191
|
-
case "provider_retry": {
|
|
1192
|
-
const secs = (ev.delayMs / 1e3).toFixed(ev.delayMs >= 1e3 ? 1 : 2);
|
|
1193
|
-
return {
|
|
1194
|
-
ts: ev.ts,
|
|
1195
|
-
source: ev.type,
|
|
1196
|
-
level: "warn",
|
|
1197
|
-
text: ev.status ? `\u27F3 retry ${ev.attempt} (HTTP ${ev.status}) after ${secs}s \u2014 ${ev.description}` : `\u27F3 retry ${ev.attempt} after ${secs}s \u2014 ${ev.description}`
|
|
1198
|
-
};
|
|
1199
|
-
}
|
|
1200
|
-
case "provider_error":
|
|
1201
|
-
return {
|
|
1202
|
-
ts: ev.ts,
|
|
1203
|
-
source: ev.type,
|
|
1204
|
-
level: "error",
|
|
1205
|
-
text: ev.status ? `provider error (HTTP ${ev.status}, ${ev.retryable ? "retryable" : "fatal"}): ${ev.description}` : `provider error (${ev.retryable ? "retryable" : "fatal"}): ${ev.description}`
|
|
1206
|
-
};
|
|
1207
|
-
case "checkpoint":
|
|
1208
|
-
return {
|
|
1209
|
-
ts: ev.ts,
|
|
1210
|
-
source: ev.type,
|
|
1211
|
-
level: "info",
|
|
1212
|
-
text: `\u2713 checkpoint #${ev.promptIndex}: "${ev.promptPreview.slice(0, 60)}"`
|
|
1213
|
-
};
|
|
1214
|
-
case "agent_spawned":
|
|
1215
|
-
return {
|
|
1216
|
-
ts: ev.ts,
|
|
1217
|
-
source: ev.type,
|
|
1218
|
-
level: "info",
|
|
1219
|
-
text: `spawned as ${ev.role}`,
|
|
1220
|
-
agentId: ev.agentId
|
|
1221
|
-
};
|
|
1222
|
-
case "agent_stopped":
|
|
1223
|
-
return {
|
|
1224
|
-
ts: ev.ts,
|
|
1225
|
-
source: ev.type,
|
|
1226
|
-
level: "info",
|
|
1227
|
-
text: "stopped",
|
|
1228
|
-
agentId: ev.agentId
|
|
1229
|
-
};
|
|
1230
|
-
case "agent_error":
|
|
1231
|
-
return {
|
|
1232
|
-
ts: ev.ts,
|
|
1233
|
-
source: ev.type,
|
|
1234
|
-
level: "error",
|
|
1235
|
-
text: `error: ${ev.error.slice(0, 80)}`,
|
|
1236
|
-
agentId: ev.agentId
|
|
1237
|
-
};
|
|
1238
|
-
case "mode_changed":
|
|
1239
|
-
return {
|
|
1240
|
-
ts: ev.ts,
|
|
1241
|
-
source: ev.type,
|
|
1242
|
-
level: "info",
|
|
1243
|
-
text: `mode: ${ev.from} \u2192 ${ev.to}`
|
|
1244
|
-
};
|
|
1245
|
-
case "skill_activated":
|
|
1246
|
-
return {
|
|
1247
|
-
ts: ev.ts,
|
|
1248
|
-
source: ev.type,
|
|
1249
|
-
level: "info",
|
|
1250
|
-
text: `skill activated: ${ev.skillName}`
|
|
1251
|
-
};
|
|
1252
|
-
case "skill_deactivated":
|
|
1253
|
-
return {
|
|
1254
|
-
ts: ev.ts,
|
|
1255
|
-
source: ev.type,
|
|
1256
|
-
level: "info",
|
|
1257
|
-
text: `skill deactivated: ${ev.skillName}`
|
|
1258
|
-
};
|
|
1259
|
-
case "message_truncated":
|
|
1260
|
-
return {
|
|
1261
|
-
ts: ev.ts,
|
|
1262
|
-
source: ev.type,
|
|
1263
|
-
level: "warn",
|
|
1264
|
-
text: ev.after < ev.before ? `message truncated: ${ev.before} \u2192 ${ev.after} tokens` : `message truncated at ${ev.after} tokens`
|
|
1265
|
-
};
|
|
1266
|
-
default:
|
|
1267
|
-
return null;
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
function projectSessionMarkers(events, sources = SESSION_MARKER_EVENT_TYPES) {
|
|
1271
|
-
const markers = [];
|
|
1272
|
-
for (const ev of events) {
|
|
1273
|
-
if (!sources.has(ev.type)) continue;
|
|
1274
|
-
const marker = sessionEventToMarker(ev);
|
|
1275
|
-
if (marker) markers.push(marker);
|
|
1276
|
-
}
|
|
1277
|
-
return markers;
|
|
1278
|
-
}
|
|
1279
|
-
var SYSTEM_INJECTION_PREFIXES = [
|
|
1280
|
-
"[MAILBOX]",
|
|
1281
|
-
"[MAILBOX BTW]",
|
|
1282
|
-
"[BY THE WAY \u2014",
|
|
1283
|
-
"[QUEUED MESSAGES \u2014",
|
|
1284
|
-
"[FLEET PULSE]",
|
|
1285
|
-
"[loop-detector]",
|
|
1286
|
-
"[SESSION RESUME FILE VALIDATION]",
|
|
1287
|
-
"[SESSION RESUME INTERRUPTED WORK]"
|
|
1288
|
-
];
|
|
1289
|
-
function isSystemInjectedMessage(text) {
|
|
1290
|
-
const trimmed = text.trimStart();
|
|
1291
|
-
for (const prefix of SYSTEM_INJECTION_PREFIXES) {
|
|
1292
|
-
if (trimmed.startsWith(prefix)) return true;
|
|
1293
|
-
}
|
|
1294
|
-
return false;
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
// src/types/spec.ts
|
|
1298
|
-
var DEFAULT_SPEC_TEMPLATE = {
|
|
1299
|
-
id: "default",
|
|
1300
|
-
name: "Default Feature Spec",
|
|
1301
|
-
description: "Standard template for feature specifications",
|
|
1302
|
-
sections: [
|
|
1303
|
-
{ type: "overview", title: "Overview", level: 1 },
|
|
1304
|
-
{ type: "requirements", title: "Requirements", level: 1 },
|
|
1305
|
-
{ type: "architecture", title: "Architecture", level: 1 },
|
|
1306
|
-
{ type: "api", title: "API Design", level: 1 },
|
|
1307
|
-
{ type: "data", title: "Data Model", level: 1 },
|
|
1308
|
-
{ type: "security", title: "Security", level: 1 },
|
|
1309
|
-
{ type: "acceptance", title: "Acceptance Criteria", level: 1 }
|
|
1310
|
-
],
|
|
1311
|
-
defaultRequirements: [
|
|
1312
|
-
{ type: "functional", priority: "high", acceptanceCriteria: [], blockedBy: [], implements: [] },
|
|
1313
|
-
{
|
|
1314
|
-
type: "non-functional",
|
|
1315
|
-
priority: "medium",
|
|
1316
|
-
acceptanceCriteria: [],
|
|
1317
|
-
blockedBy: [],
|
|
1318
|
-
implements: []
|
|
1319
|
-
}
|
|
1320
|
-
]
|
|
1321
|
-
};
|
|
1322
|
-
|
|
1323
|
-
// src/types/system-prompt.ts
|
|
1324
|
-
function flattenSystemPromptRegions(regions) {
|
|
1325
|
-
return [...regions.core, ...regions.session, ...regions.volatile];
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
// src/types/tool.ts
|
|
1329
|
-
var ToolErrorCategory = /* @__PURE__ */ ((ToolErrorCategory2) => {
|
|
1330
|
-
ToolErrorCategory2["TRANSIENT"] = "transient";
|
|
1331
|
-
ToolErrorCategory2["NOT_FOUND"] = "not_found";
|
|
1332
|
-
ToolErrorCategory2["PERMISSION"] = "permission";
|
|
1333
|
-
ToolErrorCategory2["VALIDATION"] = "validation";
|
|
1334
|
-
ToolErrorCategory2["FATAL"] = "fatal";
|
|
1335
|
-
return ToolErrorCategory2;
|
|
1336
|
-
})(ToolErrorCategory || {});
|
|
1337
|
-
|
|
1338
|
-
// src/types/tool-executor.ts
|
|
1339
|
-
var GOVERNED_TOOL_EXECUTOR_META_KEY = "toolExecutor.executeGoverned";
|
|
1340
|
-
|
|
1341
|
-
// src/types/tool-markers.ts
|
|
1342
|
-
var MALFORMED_ARG_MARKERS = ["__raw", "__raw_arguments", "_raw"];
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_SPEC_TEMPLATE,
|
|
3
|
+
FLEET_CHAT_VERBOSITY_VALUES,
|
|
4
|
+
MALFORMED_ARG_MARKERS,
|
|
5
|
+
THEME_PRESET_IDS,
|
|
6
|
+
ToolErrorCategory,
|
|
7
|
+
resolveFleetChatVerbosity
|
|
8
|
+
} from "../chunk-OJZEX73F.js";
|
|
9
|
+
import {
|
|
10
|
+
diffRegistry,
|
|
11
|
+
validateRegistryManifest
|
|
12
|
+
} from "../chunk-IYFBFX34.js";
|
|
13
|
+
import {
|
|
14
|
+
MEMORY_TYPE_LABELS,
|
|
15
|
+
defineMemoryCapability
|
|
16
|
+
} from "../chunk-57GEWK5X.js";
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_MODES
|
|
19
|
+
} from "../chunk-2FK4WTFF.js";
|
|
20
|
+
import {
|
|
21
|
+
CONTEXT_WINDOW_MODES,
|
|
22
|
+
CONTEXT_WINDOW_MODE_PINNED_META_KEY,
|
|
23
|
+
DEFAULT_AUTONOMY_CONFIG,
|
|
24
|
+
DEFAULT_CIRCUIT_BREAKER_CONFIG,
|
|
25
|
+
DEFAULT_CONTEXT_CONFIG,
|
|
26
|
+
DEFAULT_CONTEXT_WINDOW_MODE_ID,
|
|
27
|
+
DEFAULT_SESSION_LOGGING_CONFIG,
|
|
28
|
+
DEFAULT_SESSION_PRUNE_DAYS,
|
|
29
|
+
DEFAULT_TOOLS_CONFIG,
|
|
30
|
+
DEPRECATED_CONTEXT_WINDOW_MODE_ALIASES,
|
|
31
|
+
LARGE_WINDOW_DEEP_MODE_THRESHOLD,
|
|
32
|
+
formatContextWindowModeList,
|
|
33
|
+
getContextWindowMode,
|
|
34
|
+
isContextWindowModeId,
|
|
35
|
+
isContextWindowModeSelectionId,
|
|
36
|
+
isDeprecatedContextWindowModeId,
|
|
37
|
+
listContextWindowModes,
|
|
38
|
+
normalizeContextWindowModeId,
|
|
39
|
+
resolveContextWindowPolicy
|
|
40
|
+
} from "../chunk-ZZ4V3WIZ.js";
|
|
41
|
+
import {
|
|
42
|
+
GOVERNED_TOOL_EXECUTOR_META_KEY
|
|
43
|
+
} from "../chunk-XBDP4QPW.js";
|
|
44
|
+
import {
|
|
45
|
+
BUILTIN_PROMPT_CATEGORIES,
|
|
46
|
+
PROMPT_CATEGORY_LABELS,
|
|
47
|
+
isBuiltinCategory
|
|
48
|
+
} from "../chunk-KDQJCT2J.js";
|
|
49
|
+
import {
|
|
50
|
+
DESIGN_STACKS,
|
|
51
|
+
KNOWN_TOKEN_GROUPS,
|
|
52
|
+
KNOWN_TOKEN_NAMES,
|
|
53
|
+
isDesignStack
|
|
54
|
+
} from "../chunk-G5S3S5ZN.js";
|
|
55
|
+
import {
|
|
56
|
+
ProviderError,
|
|
57
|
+
REASONING_EFFORT_LEVELS,
|
|
58
|
+
StreamHangError,
|
|
59
|
+
classifyProviderError,
|
|
60
|
+
effectiveInputTokens,
|
|
61
|
+
freshInputTokens,
|
|
62
|
+
isContextOverflowShaped,
|
|
63
|
+
isFallbackWorthy,
|
|
64
|
+
isReasoningEffort,
|
|
65
|
+
isRetryableKind,
|
|
66
|
+
promptCacheHitRatio
|
|
67
|
+
} from "../chunk-NFAYHPRH.js";
|
|
68
|
+
import {
|
|
69
|
+
CHAT_MARKER_SOURCES,
|
|
70
|
+
SESSION_MARKER_EVENT_TYPES,
|
|
71
|
+
SYSTEM_INJECTION_PREFIXES,
|
|
72
|
+
isSystemInjectedMessage,
|
|
73
|
+
projectSessionMarkers,
|
|
74
|
+
sessionEventToMarker
|
|
75
|
+
} from "../chunk-KSJ5UTP7.js";
|
|
76
|
+
import {
|
|
77
|
+
flattenSystemPromptRegions
|
|
78
|
+
} from "../chunk-CB2HFKTP.js";
|
|
79
|
+
import {
|
|
80
|
+
DEFAULT_TUI_THINKING_WORD,
|
|
81
|
+
MAX_TUI_THINKING_WORD_LENGTH,
|
|
82
|
+
MAX_WRONGPROXY_URL_LENGTH,
|
|
83
|
+
normalizeTokenSavingTier,
|
|
84
|
+
normalizeTuiThinkingWord,
|
|
85
|
+
resolveTokenSavingTier
|
|
86
|
+
} from "../chunk-KJ2ZTQSL.js";
|
|
87
|
+
import "../chunk-B4AMLZPB.js";
|
|
88
|
+
import {
|
|
89
|
+
isImageBlock,
|
|
90
|
+
isTextBlock,
|
|
91
|
+
isToolResultBlock,
|
|
92
|
+
isToolUseBlock
|
|
93
|
+
} from "../chunk-O37BQ65S.js";
|
|
94
|
+
import {
|
|
95
|
+
AgentError,
|
|
96
|
+
ConfigError,
|
|
97
|
+
ERROR_CODES,
|
|
98
|
+
FetchError,
|
|
99
|
+
FsError,
|
|
100
|
+
ParseError,
|
|
101
|
+
PluginError,
|
|
102
|
+
SddError,
|
|
103
|
+
SessionError,
|
|
104
|
+
ToolError,
|
|
105
|
+
ToolValidationError,
|
|
106
|
+
WrongStackError,
|
|
107
|
+
isAgentError,
|
|
108
|
+
isConfigError,
|
|
109
|
+
isFetchError,
|
|
110
|
+
isFsError,
|
|
111
|
+
isParseError,
|
|
112
|
+
isPluginError,
|
|
113
|
+
isSddError,
|
|
114
|
+
isSessionError,
|
|
115
|
+
isToolError,
|
|
116
|
+
isToolValidationError,
|
|
117
|
+
isWrongStackError,
|
|
118
|
+
toWrongStackError
|
|
119
|
+
} from "../chunk-WOEZV3Q4.js";
|
|
120
|
+
import "../chunk-TBRL2RCC.js";
|
|
121
|
+
import "../chunk-PFZO3C6H.js";
|
|
1343
122
|
export {
|
|
1344
123
|
AgentError,
|
|
1345
124
|
BUILTIN_PROMPT_CATEGORIES,
|