sneakoscope 4.0.4 → 4.0.5
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/README.md +9 -9
- package/crates/sks-core/Cargo.lock +1 -1
- package/crates/sks-core/Cargo.toml +1 -1
- package/crates/sks-core/src/main.rs +1 -1
- package/dist/bin/sks.js +1 -1
- package/dist/core/codex-app/glm-profile-schema.js +5 -1
- package/dist/core/commands/glm-command.js +15 -1
- package/dist/core/commands/mad-sks-command.js +65 -9
- package/dist/core/fsx.js +1 -1
- package/dist/core/perf/lru-cache.js +33 -0
- package/dist/core/providers/glm/glm-52-profile.js +14 -7
- package/dist/core/providers/glm/glm-52-request.js +40 -12
- package/dist/core/providers/glm/glm-52-response-guard.js +1 -2
- package/dist/core/providers/glm/glm-52-settings.js +50 -8
- package/dist/core/providers/glm/glm-bench.js +90 -0
- package/dist/core/providers/glm/glm-context-budget.js +15 -0
- package/dist/core/providers/glm/glm-context-cache.js +9 -0
- package/dist/core/providers/glm/glm-latency-trace.js +40 -0
- package/dist/core/providers/glm/glm-mad-launch.js +18 -3
- package/dist/core/providers/glm/glm-mad-mode.js +48 -20
- package/dist/core/providers/glm/glm-model-meta-cache.js +19 -0
- package/dist/core/providers/glm/glm-profile-resolver.js +104 -0
- package/dist/core/providers/glm/glm-reasoning-policy.js +15 -0
- package/dist/core/providers/glm/glm-request-cache.js +47 -0
- package/dist/core/providers/glm/glm-speed-context.js +82 -0
- package/dist/core/providers/glm/glm-speed-gate.js +40 -0
- package/dist/core/providers/glm/glm-speed-output-parser.js +40 -0
- package/dist/core/providers/glm/glm-tool-schema-cache.js +19 -0
- package/dist/core/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { nowIso, writeJsonAtomic } from '../../fsx.js';
|
|
3
|
+
export function createEmptyGlmLatencyTrace(mode) {
|
|
4
|
+
return {
|
|
5
|
+
schema: 'sks.glm-latency-trace.v1',
|
|
6
|
+
version: '4.0.5',
|
|
7
|
+
mode,
|
|
8
|
+
total_ms: 0,
|
|
9
|
+
preflight_ms: 0,
|
|
10
|
+
key_resolve_ms: 0,
|
|
11
|
+
model_meta_ms: 0,
|
|
12
|
+
task_classify_ms: 0,
|
|
13
|
+
context_build_ms: 0,
|
|
14
|
+
context_estimated_tokens: 0,
|
|
15
|
+
context_cache_hit: false,
|
|
16
|
+
tool_schema_build_ms: 0,
|
|
17
|
+
tool_schema_cache_hit: false,
|
|
18
|
+
request_build_ms: 0,
|
|
19
|
+
request_encode_ms: 0,
|
|
20
|
+
encoded_request_cache_hit: false,
|
|
21
|
+
openrouter_ttft_ms: null,
|
|
22
|
+
openrouter_total_ms: null,
|
|
23
|
+
output_parse_ms: 0,
|
|
24
|
+
model_guard_ms: 0,
|
|
25
|
+
patch_apply_ms: 0,
|
|
26
|
+
deterministic_gate_ms: 0,
|
|
27
|
+
proof_write_ms: 0
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export async function writeGlmLatencyTrace(root, trace) {
|
|
31
|
+
const safeTrace = redactTrace(trace);
|
|
32
|
+
const filename = `${nowIso().replace(/[:.]/g, '-')}-glm-${trace.mode}-trace.json`;
|
|
33
|
+
const out = path.join(root, '.sneakoscope', 'glm', 'traces', filename);
|
|
34
|
+
await writeJsonAtomic(out, safeTrace);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
function redactTrace(trace) {
|
|
38
|
+
return JSON.parse(JSON.stringify(trace).replace(/sk-or-[A-Za-z0-9_-]+/g, 'sk-or-...redacted...'));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=glm-latency-trace.js.map
|
|
@@ -3,14 +3,19 @@ import path from 'node:path';
|
|
|
3
3
|
import { nowIso, writeTextAtomic } from '../../fsx.js';
|
|
4
4
|
import { resolveOpenRouterApiKey, openRouterSecretPaths } from '../openrouter/openrouter-secret-store.js';
|
|
5
5
|
import { GLM_52_OPENROUTER_MODEL } from './glm-52-settings.js';
|
|
6
|
+
import { resolveGlmProfileFromArgs } from './glm-profile-resolver.js';
|
|
6
7
|
export const GLM_MAD_PROFILE_ID = 'sks/glm-5.2-mad';
|
|
7
8
|
export const OPENROUTER_CODEX_PROVIDER = 'openrouter';
|
|
8
|
-
export function buildMadGlmLaunchProfileNoWrite() {
|
|
9
|
+
export function buildMadGlmLaunchProfileNoWrite(args = []) {
|
|
10
|
+
const profile = resolveGlmProfileFromArgs(args);
|
|
11
|
+
const effort = codexReasoningEffortForProfile(profile);
|
|
9
12
|
return {
|
|
10
13
|
schema: 'sks.glm-mad-launch-profile.v1',
|
|
11
14
|
profile_name: GLM_MAD_PROFILE_ID,
|
|
12
15
|
provider: OPENROUTER_CODEX_PROVIDER,
|
|
13
16
|
model: GLM_52_OPENROUTER_MODEL,
|
|
17
|
+
glm_profile: profile.name,
|
|
18
|
+
glm_mode: profile.mode,
|
|
14
19
|
launch_args: [
|
|
15
20
|
'--sandbox',
|
|
16
21
|
'danger-full-access',
|
|
@@ -19,7 +24,7 @@ export function buildMadGlmLaunchProfileNoWrite() {
|
|
|
19
24
|
'-c',
|
|
20
25
|
'service_tier=fast',
|
|
21
26
|
'-c',
|
|
22
|
-
|
|
27
|
+
`model_reasoning_effort=${effort}`,
|
|
23
28
|
'-c',
|
|
24
29
|
'model_provider="openrouter"',
|
|
25
30
|
'-c',
|
|
@@ -37,7 +42,7 @@ export function buildMadGlmLaunchProfileNoWrite() {
|
|
|
37
42
|
],
|
|
38
43
|
sandbox_mode: 'danger-full-access',
|
|
39
44
|
approval_policy: 'never',
|
|
40
|
-
model_reasoning_effort:
|
|
45
|
+
model_reasoning_effort: effort,
|
|
41
46
|
service_tier: 'fast',
|
|
42
47
|
gpt_fallback_allowed: false,
|
|
43
48
|
writes_user_codex_config: false
|
|
@@ -94,6 +99,9 @@ export function buildMadGlmLaunchArtifact(input) {
|
|
|
94
99
|
mission_id: input.missionId,
|
|
95
100
|
provider: profile.provider,
|
|
96
101
|
model: profile.model,
|
|
102
|
+
glm_profile: profile.glm_profile,
|
|
103
|
+
glm_mode: profile.glm_mode,
|
|
104
|
+
model_reasoning_effort: profile.model_reasoning_effort,
|
|
97
105
|
profile_name: profile.profile_name,
|
|
98
106
|
strict_model_lock: true,
|
|
99
107
|
gpt_fallback_allowed: false,
|
|
@@ -110,4 +118,11 @@ export function buildMadGlmLaunchArtifact(input) {
|
|
|
110
118
|
function shellQuote(value) {
|
|
111
119
|
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
112
120
|
}
|
|
121
|
+
function codexReasoningEffortForProfile(profile) {
|
|
122
|
+
if (profile.name === 'xhigh')
|
|
123
|
+
return 'xhigh';
|
|
124
|
+
if (profile.name === 'deep' || profile.name === 'strict')
|
|
125
|
+
return 'high';
|
|
126
|
+
return 'xhigh';
|
|
127
|
+
}
|
|
113
128
|
//# sourceMappingURL=glm-mad-launch.js.map
|
|
@@ -11,23 +11,33 @@ import { redactOpenRouterKey } from '../../security/redact-secrets.js';
|
|
|
11
11
|
import { buildGlmCodexAppModelProfile } from './glm-52-profile.js';
|
|
12
12
|
import { buildGlm52KeyValidationRequest, buildGlm52Request } from './glm-52-request.js';
|
|
13
13
|
import { assertGlm52ActualModel } from './glm-52-response-guard.js';
|
|
14
|
-
import { GLM_52_OPENROUTER_MODEL,
|
|
14
|
+
import { GLM_52_OPENROUTER_MODEL, OPENROUTER_CHAT_COMPLETIONS_URL } from './glm-52-settings.js';
|
|
15
|
+
import { resolveGlmProfileFromArgs } from './glm-profile-resolver.js';
|
|
16
|
+
import { createEmptyGlmLatencyTrace, writeGlmLatencyTrace } from './glm-latency-trace.js';
|
|
15
17
|
export async function runMadGlmMode(args = [], adapters = {}) {
|
|
16
18
|
const runtime = buildDefaultAdapters(adapters);
|
|
17
19
|
const repair = flag(args, '--repair');
|
|
18
20
|
const noSaveKey = flag(args, '--no-save-key');
|
|
19
21
|
const skipValidation = flag(args, '--skip-validation');
|
|
20
22
|
const json = flag(args, '--json');
|
|
23
|
+
const selectedProfile = resolveGlmProfileFromArgs(args);
|
|
21
24
|
const profile = buildGlmCodexAppModelProfile();
|
|
22
25
|
let result;
|
|
23
|
-
if (
|
|
26
|
+
if (selectedProfile.blockers.length) {
|
|
27
|
+
result = baseResult({
|
|
28
|
+
status: 'blocked',
|
|
29
|
+
blockers: selectedProfile.blockers,
|
|
30
|
+
warnings: []
|
|
31
|
+
}, selectedProfile);
|
|
32
|
+
}
|
|
33
|
+
else if (repair) {
|
|
24
34
|
const key = await runtime.promptSecret('OpenRouter API key is required for GLM 5.2 mode.\nEnter OpenRouter API key: ');
|
|
25
35
|
if (!key) {
|
|
26
36
|
result = baseResult({
|
|
27
37
|
status: 'blocked',
|
|
28
38
|
blockers: ['glm_key_prompt_cancelled'],
|
|
29
39
|
warnings: []
|
|
30
|
-
});
|
|
40
|
+
}, selectedProfile);
|
|
31
41
|
}
|
|
32
42
|
else {
|
|
33
43
|
if (!noSaveKey)
|
|
@@ -43,14 +53,14 @@ export async function runMadGlmMode(args = [], adapters = {}) {
|
|
|
43
53
|
key_preview: redactOpenRouterKey(key),
|
|
44
54
|
blockers: [],
|
|
45
55
|
warnings: noSaveKey ? ['openrouter_key_not_saved'] : []
|
|
46
|
-
})
|
|
56
|
+
}, selectedProfile)
|
|
47
57
|
: baseResult({
|
|
48
58
|
status: 'blocked',
|
|
49
59
|
openrouter_key_source: noSaveKey ? 'prompt' : 'user-secret-store',
|
|
50
60
|
key_preview: redactOpenRouterKey(key),
|
|
51
61
|
blockers: [validation.error.code],
|
|
52
62
|
warnings: []
|
|
53
|
-
});
|
|
63
|
+
}, selectedProfile);
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
else {
|
|
@@ -58,7 +68,7 @@ export async function runMadGlmMode(args = [], adapters = {}) {
|
|
|
58
68
|
if (!resolved.key && process.stdin.isTTY) {
|
|
59
69
|
const key = await runtime.promptSecret('OpenRouter API key is required for GLM 5.2 mode.\nEnter OpenRouter API key: ');
|
|
60
70
|
if (!key) {
|
|
61
|
-
result = baseResult({ status: 'blocked', blockers: ['glm_key_prompt_cancelled'], warnings: [] });
|
|
71
|
+
result = baseResult({ status: 'blocked', blockers: ['glm_key_prompt_cancelled'], warnings: [] }, selectedProfile);
|
|
62
72
|
}
|
|
63
73
|
else {
|
|
64
74
|
const save = noSaveKey ? false : await runtime.promptConfirm('Save this key for future SKS GLM runs? [Y/n] ', true);
|
|
@@ -70,7 +80,7 @@ export async function runMadGlmMode(args = [], adapters = {}) {
|
|
|
70
80
|
key_preview: redactOpenRouterKey(key),
|
|
71
81
|
blockers: [],
|
|
72
82
|
warnings: save ? [] : ['openrouter_key_not_saved']
|
|
73
|
-
});
|
|
83
|
+
}, selectedProfile);
|
|
74
84
|
}
|
|
75
85
|
}
|
|
76
86
|
else if (!resolved.key) {
|
|
@@ -78,7 +88,7 @@ export async function runMadGlmMode(args = [], adapters = {}) {
|
|
|
78
88
|
status: 'blocked',
|
|
79
89
|
blockers: resolved.blockers,
|
|
80
90
|
warnings: ['set_OPENROUTER_API_KEY_or_run_sks_--mad_--glm_--repair']
|
|
81
|
-
});
|
|
91
|
+
}, selectedProfile);
|
|
82
92
|
}
|
|
83
93
|
else {
|
|
84
94
|
result = baseResult({
|
|
@@ -87,10 +97,19 @@ export async function runMadGlmMode(args = [], adapters = {}) {
|
|
|
87
97
|
key_preview: resolved.key_preview,
|
|
88
98
|
blockers: [],
|
|
89
99
|
warnings: resolved.warnings
|
|
90
|
-
});
|
|
100
|
+
}, selectedProfile);
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
|
-
await writeGlmModeArtifacts(runtime.cwd, result, profile, runtime.nowIso()).catch(() => undefined);
|
|
103
|
+
await writeGlmModeArtifacts(runtime.cwd, result, profile, selectedProfile, runtime.nowIso()).catch(() => undefined);
|
|
104
|
+
if (flag(args, '--trace')) {
|
|
105
|
+
await writeGlmLatencyTrace(runtime.cwd, {
|
|
106
|
+
...createEmptyGlmLatencyTrace(selectedProfile.name),
|
|
107
|
+
context_estimated_tokens: selectedProfile.name === 'speed' ? 16_000 : 64_000,
|
|
108
|
+
request_encode_ms: 1,
|
|
109
|
+
encoded_request_cache_hit: false,
|
|
110
|
+
provider: 'openrouter'
|
|
111
|
+
}).catch(() => undefined);
|
|
112
|
+
}
|
|
94
113
|
if (json)
|
|
95
114
|
printJson(result);
|
|
96
115
|
else
|
|
@@ -99,12 +118,13 @@ export async function runMadGlmMode(args = [], adapters = {}) {
|
|
|
99
118
|
process.exitCode = 1;
|
|
100
119
|
return result;
|
|
101
120
|
}
|
|
102
|
-
function baseResult(input) {
|
|
121
|
+
function baseResult(input, profile) {
|
|
103
122
|
const result = {
|
|
104
123
|
schema: 'sks.glm-mode-result.v1',
|
|
105
124
|
ok: input.blockers.length === 0 && input.status !== 'failed',
|
|
106
125
|
status: input.status,
|
|
107
|
-
mode:
|
|
126
|
+
mode: profile.mode,
|
|
127
|
+
profile: profile.name,
|
|
108
128
|
provider: 'openrouter',
|
|
109
129
|
model: GLM_52_OPENROUTER_MODEL,
|
|
110
130
|
requested_model: GLM_52_OPENROUTER_MODEL,
|
|
@@ -166,25 +186,32 @@ function validationValue(actualModel) {
|
|
|
166
186
|
gpt_fallback_allowed: false
|
|
167
187
|
};
|
|
168
188
|
}
|
|
169
|
-
async function writeGlmModeArtifacts(cwd, result, profile, generatedAt) {
|
|
189
|
+
async function writeGlmModeArtifacts(cwd, result, profile, selectedProfile, generatedAt) {
|
|
170
190
|
const dir = path.join(cwd, '.sneakoscope', 'glm');
|
|
171
191
|
await writeJsonAtomic(path.join(dir, 'mad-glm-session.json'), {
|
|
172
192
|
schema: 'sks.glm-mad-session.v1',
|
|
173
193
|
generated_at: generatedAt,
|
|
174
194
|
result,
|
|
175
|
-
profile_id: profile.id
|
|
195
|
+
profile_id: profile.id,
|
|
196
|
+
selected_profile: selectedProfile.name
|
|
176
197
|
});
|
|
177
198
|
await writeJsonAtomic(path.join(dir, 'openrouter-request-summary.json'), {
|
|
178
199
|
schema: 'sks.openrouter-request-summary.v1',
|
|
179
200
|
generated_at: generatedAt,
|
|
180
201
|
endpoint: OPENROUTER_CHAT_COMPLETIONS_URL,
|
|
181
202
|
model: GLM_52_OPENROUTER_MODEL,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
203
|
+
mode: selectedProfile.mode,
|
|
204
|
+
profile: selectedProfile.name,
|
|
205
|
+
temperature: selectedProfile.temperature,
|
|
206
|
+
top_p: selectedProfile.top_p,
|
|
207
|
+
reasoning_effort: selectedProfile.reasoning_effort || 'xhigh',
|
|
208
|
+
max_tokens: selectedProfile.max_tokens,
|
|
209
|
+
tool_choice: selectedProfile.tool_choice,
|
|
210
|
+
parallel_tool_calls: selectedProfile.parallel_tool_calls,
|
|
211
|
+
stream: selectedProfile.stream,
|
|
186
212
|
provider_allow_fallbacks: false,
|
|
187
|
-
|
|
213
|
+
provider_sort: selectedProfile.provider.sort || null,
|
|
214
|
+
require_parameters: selectedProfile.provider.require_parameters,
|
|
188
215
|
key_source: result.openrouter_key_source || null,
|
|
189
216
|
key_preview: result.key_preview || null
|
|
190
217
|
});
|
|
@@ -200,7 +227,7 @@ async function writeGlmModeArtifacts(cwd, result, profile, generatedAt) {
|
|
|
200
227
|
});
|
|
201
228
|
}
|
|
202
229
|
function printHumanGlmResult(result, log) {
|
|
203
|
-
log(`GLM 5.2 MAD mode: ${result.ok ? result.status : 'blocked'}`);
|
|
230
|
+
log(`GLM 5.2 MAD mode: ${result.ok ? result.status : 'blocked'} (${result.profile})`);
|
|
204
231
|
log(`Model: ${result.model}`);
|
|
205
232
|
log(`GPT fallback: ${result.gpt_fallback_allowed ? 'allowed' : 'blocked'}`);
|
|
206
233
|
if (result.openrouter_key_source)
|
|
@@ -233,6 +260,7 @@ async function promptConfirmLine(prompt, defaultYes) {
|
|
|
233
260
|
export function buildGlmModeDryRunRequest() {
|
|
234
261
|
return buildGlm52Request({
|
|
235
262
|
messages: [{ role: 'user', content: 'SKS GLM dry run.' }],
|
|
263
|
+
profile: 'speed',
|
|
236
264
|
stream: false,
|
|
237
265
|
maxTokens: 1,
|
|
238
266
|
toolChoice: 'none',
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SksLruCache } from '../../perf/lru-cache.js';
|
|
2
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
3
|
+
export function createGlmModelMetaCache(maxEntries = 16, ttlMs = DAY_MS) {
|
|
4
|
+
const cache = new SksLruCache(maxEntries);
|
|
5
|
+
return {
|
|
6
|
+
get(model, now = Date.now()) {
|
|
7
|
+
const entry = cache.get(model);
|
|
8
|
+
if (!entry || entry.expiresAt <= now)
|
|
9
|
+
return null;
|
|
10
|
+
return entry;
|
|
11
|
+
},
|
|
12
|
+
set(model, reasoning, now = Date.now()) {
|
|
13
|
+
const entry = { model, reasoning, createdAt: now, expiresAt: now + ttlMs };
|
|
14
|
+
cache.set(model, entry, now);
|
|
15
|
+
return entry;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=glm-model-meta-cache.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { readOption } from '../../../cli/args.js';
|
|
2
|
+
import { GLM_DEEP_MODE, GLM_DEEP_PROFILE, GLM_SPEED_MODE, GLM_SPEED_PROFILE, GLM_STRICT_MODE, GLM_STRICT_PROFILE, GLM_XHIGH_MODE, GLM_XHIGH_PROFILE } from './glm-52-settings.js';
|
|
3
|
+
export function resolveGlmProfileFromArgs(args = []) {
|
|
4
|
+
const list = args.map(String);
|
|
5
|
+
const exactProvider = readOption(list, '--exact-provider', null);
|
|
6
|
+
const providerBlockers = exactProvider && !isValidOpenRouterProviderSlug(exactProvider)
|
|
7
|
+
? [`invalid_openrouter_provider_slug:${exactProvider}`]
|
|
8
|
+
: [];
|
|
9
|
+
const base = list.includes('--xhigh')
|
|
10
|
+
? profileFromConst('xhigh')
|
|
11
|
+
: list.includes('--strict')
|
|
12
|
+
? profileFromConst('strict')
|
|
13
|
+
: list.includes('--deep')
|
|
14
|
+
? profileFromConst('deep')
|
|
15
|
+
: profileFromConst('speed');
|
|
16
|
+
const provider = exactProvider && !providerBlockers.length
|
|
17
|
+
? {
|
|
18
|
+
allow_fallbacks: false,
|
|
19
|
+
require_parameters: base.provider.require_parameters,
|
|
20
|
+
order: [exactProvider]
|
|
21
|
+
}
|
|
22
|
+
: list.includes('--ttft')
|
|
23
|
+
? {
|
|
24
|
+
...base.provider,
|
|
25
|
+
sort: 'latency',
|
|
26
|
+
preferred_max_latency: { p50: 1.5, p90: 4 }
|
|
27
|
+
}
|
|
28
|
+
: base.provider;
|
|
29
|
+
return {
|
|
30
|
+
...base,
|
|
31
|
+
provider,
|
|
32
|
+
blockers: providerBlockers
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function profileFromConst(name) {
|
|
36
|
+
if (name === 'deep') {
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
mode: GLM_DEEP_MODE,
|
|
40
|
+
stream: GLM_DEEP_PROFILE.stream,
|
|
41
|
+
max_tokens: GLM_DEEP_PROFILE.max_tokens,
|
|
42
|
+
temperature: GLM_DEEP_PROFILE.temperature,
|
|
43
|
+
top_p: GLM_DEEP_PROFILE.top_p,
|
|
44
|
+
tool_choice: GLM_DEEP_PROFILE.tool_choice,
|
|
45
|
+
parallel_tool_calls: GLM_DEEP_PROFILE.parallel_tool_calls,
|
|
46
|
+
provider: GLM_DEEP_PROFILE.provider,
|
|
47
|
+
reasoning_effort: GLM_DEEP_PROFILE.reasoning_effort,
|
|
48
|
+
blockers: []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (name === 'xhigh') {
|
|
52
|
+
return {
|
|
53
|
+
...profileFromConst('deep'),
|
|
54
|
+
name,
|
|
55
|
+
mode: GLM_XHIGH_MODE,
|
|
56
|
+
max_tokens: GLM_XHIGH_PROFILE.max_tokens,
|
|
57
|
+
reasoning_effort: GLM_XHIGH_PROFILE.reasoning_effort,
|
|
58
|
+
blockers: []
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (name === 'strict') {
|
|
62
|
+
return {
|
|
63
|
+
...profileFromConst('deep'),
|
|
64
|
+
name,
|
|
65
|
+
mode: GLM_STRICT_MODE,
|
|
66
|
+
response_format: {
|
|
67
|
+
type: 'json_schema',
|
|
68
|
+
json_schema: {
|
|
69
|
+
name: 'sks_glm_strict_proof',
|
|
70
|
+
strict: true,
|
|
71
|
+
schema: {
|
|
72
|
+
type: 'object',
|
|
73
|
+
additionalProperties: false,
|
|
74
|
+
properties: {
|
|
75
|
+
summary: { type: 'string' },
|
|
76
|
+
patch: { type: 'string' },
|
|
77
|
+
proof: { type: 'object' }
|
|
78
|
+
},
|
|
79
|
+
required: ['summary', 'patch', 'proof']
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
blockers: []
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
name,
|
|
88
|
+
mode: GLM_SPEED_MODE,
|
|
89
|
+
stream: GLM_SPEED_PROFILE.stream,
|
|
90
|
+
max_tokens: GLM_SPEED_PROFILE.max_tokens,
|
|
91
|
+
temperature: GLM_SPEED_PROFILE.temperature,
|
|
92
|
+
top_p: GLM_SPEED_PROFILE.top_p,
|
|
93
|
+
tool_choice: GLM_SPEED_PROFILE.tool_choice,
|
|
94
|
+
parallel_tool_calls: GLM_SPEED_PROFILE.parallel_tool_calls,
|
|
95
|
+
provider: GLM_SPEED_PROFILE.provider,
|
|
96
|
+
reasoning_effort: GLM_SPEED_PROFILE.reasoning_effort,
|
|
97
|
+
stop: ['</sks_patch>'],
|
|
98
|
+
blockers: []
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export function isValidOpenRouterProviderSlug(value) {
|
|
102
|
+
return /^(?!.*(?:^|\/)\.\.?(?:\/|$))[a-z0-9][a-z0-9._-]{0,63}(?:\/[a-z0-9][a-z0-9._-]{0,63}){0,3}$/i.test(value);
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=glm-profile-resolver.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const FAST_REASONING_ORDER = ['none', 'minimal', 'low'];
|
|
2
|
+
export function buildFastReasoningConfig(meta = null) {
|
|
3
|
+
if (meta?.mandatory === true)
|
|
4
|
+
return { exclude: true };
|
|
5
|
+
const supported = new Set(meta?.supported_efforts || []);
|
|
6
|
+
for (const effort of FAST_REASONING_ORDER) {
|
|
7
|
+
if (supported.has(effort))
|
|
8
|
+
return { effort, exclude: true };
|
|
9
|
+
}
|
|
10
|
+
return { exclude: true };
|
|
11
|
+
}
|
|
12
|
+
export function buildDeepReasoningConfig(effort) {
|
|
13
|
+
return { effort, exclude: true };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=glm-reasoning-policy.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { SksLruCache } from '../../perf/lru-cache.js';
|
|
3
|
+
export function createGlmEncodedRequestCache(maxEntries = 128) {
|
|
4
|
+
return new SksLruCache(maxEntries);
|
|
5
|
+
}
|
|
6
|
+
export function encodeGlmRequestWithCache(request, cache = defaultEncodedRequestCache) {
|
|
7
|
+
const key = digestRequestForCache(request);
|
|
8
|
+
const hit = cache.get(key);
|
|
9
|
+
if (hit)
|
|
10
|
+
return { entry: hit, cacheHit: true };
|
|
11
|
+
const body = JSON.stringify(request);
|
|
12
|
+
const entry = {
|
|
13
|
+
key,
|
|
14
|
+
bodySha256: crypto.createHash('sha256').update(body).digest('hex'),
|
|
15
|
+
byteLength: Buffer.byteLength(body),
|
|
16
|
+
createdAt: Date.now(),
|
|
17
|
+
bodyStored: false
|
|
18
|
+
};
|
|
19
|
+
cache.set(key, entry);
|
|
20
|
+
return { entry, cacheHit: false };
|
|
21
|
+
}
|
|
22
|
+
export function digestRequestForCache(request) {
|
|
23
|
+
const safe = {
|
|
24
|
+
model: request.model,
|
|
25
|
+
messages: request.messages,
|
|
26
|
+
tools: request.tools || null,
|
|
27
|
+
response_format: request.response_format || null,
|
|
28
|
+
provider: request.provider || null,
|
|
29
|
+
max_tokens: request.max_tokens || null,
|
|
30
|
+
temperature: request.temperature || null,
|
|
31
|
+
top_p: request.top_p || null,
|
|
32
|
+
tool_choice: request.tool_choice || null,
|
|
33
|
+
parallel_tool_calls: request.parallel_tool_calls || null,
|
|
34
|
+
reasoning: request.reasoning || null
|
|
35
|
+
};
|
|
36
|
+
return crypto.createHash('sha256').update(stableStringify(safe)).digest('hex');
|
|
37
|
+
}
|
|
38
|
+
function stableStringify(value) {
|
|
39
|
+
if (!value || typeof value !== 'object')
|
|
40
|
+
return JSON.stringify(value);
|
|
41
|
+
if (Array.isArray(value))
|
|
42
|
+
return `[${value.map(stableStringify).join(',')}]`;
|
|
43
|
+
const object = value;
|
|
44
|
+
return `{${Object.keys(object).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(object[key])}`).join(',')}}`;
|
|
45
|
+
}
|
|
46
|
+
const defaultEncodedRequestCache = createGlmEncodedRequestCache();
|
|
47
|
+
//# sourceMappingURL=glm-request-cache.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { estimateGlmTokens, GLM_SPEED_CONTEXT_HARD_CAP_TOKENS, GLM_SPEED_CONTEXT_TARGET_TOKENS, trimToEstimatedTokens } from './glm-context-budget.js';
|
|
4
|
+
const GENERATED_PATH = /(^|\/)(dist|node_modules|coverage|\.git)(\/|$)|(\.generated\.|\.map$)/;
|
|
5
|
+
const DEFAULT_MAX_FILE_BYTES = 64 * 1024;
|
|
6
|
+
export async function buildGlmSpeedContext(input) {
|
|
7
|
+
const maxTokens = Math.min(input.maxTokens || GLM_SPEED_CONTEXT_TARGET_TOKENS, GLM_SPEED_CONTEXT_HARD_CAP_TOKENS);
|
|
8
|
+
const maxFileBytes = Math.max(1024, input.maxFileBytes || DEFAULT_MAX_FILE_BYTES);
|
|
9
|
+
const sections = [];
|
|
10
|
+
const omitted = [];
|
|
11
|
+
addSection(sections, 'task', input.task);
|
|
12
|
+
addSection(sections, 'constraints', 'GLM speed mode: compact context, one-shot patch, no GPT/OpenAI fallback, no full TriWiki/proof-bank/repo dump.');
|
|
13
|
+
if (input.gitStatus)
|
|
14
|
+
addSection(sections, 'git_status', input.gitStatus);
|
|
15
|
+
if (input.lastError)
|
|
16
|
+
addSection(sections, 'error', trimToEstimatedTokens(input.lastError, 2000));
|
|
17
|
+
const readFile = input.readFile || (async () => null);
|
|
18
|
+
for (const mentioned of input.mentionedPaths || []) {
|
|
19
|
+
const normalized = mentioned.replace(/\\/g, '/');
|
|
20
|
+
if (GENERATED_PATH.test(normalized)) {
|
|
21
|
+
omitted.push({ kind: 'generated_or_large_path', path: mentioned, reason: 'speed_context_excludes_generated_or_vendor_paths' });
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const absolute = path.isAbsolute(mentioned) ? mentioned : path.join(input.cwd, mentioned);
|
|
25
|
+
const rawText = input.readFileSnippet ? await input.readFileSnippet(absolute, maxFileBytes) : await readFile(absolute);
|
|
26
|
+
const text = rawText === null ? null : trimToUtf8Bytes(rawText, maxFileBytes);
|
|
27
|
+
if (text === null) {
|
|
28
|
+
omitted.push({ kind: 'file_snippet', path: mentioned, reason: 'unreadable_or_missing' });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (Buffer.byteLength(rawText || '', 'utf8') > maxFileBytes) {
|
|
32
|
+
omitted.push({ kind: 'file_snippet_tail', path: mentioned, reason: 'speed_context_file_byte_budget' });
|
|
33
|
+
}
|
|
34
|
+
addSection(sections, 'file_snippet', trimToEstimatedTokens(text, 2400), path.relative(input.cwd, absolute) || mentioned);
|
|
35
|
+
}
|
|
36
|
+
const compact = enforceBudget(sections, omitted, maxTokens);
|
|
37
|
+
return {
|
|
38
|
+
schema: 'sks.glm-speed-context.v1',
|
|
39
|
+
digest: digestJson({ sections: compact.sections, omitted: compact.omitted }),
|
|
40
|
+
estimatedTokens: compact.sections.reduce((sum, section) => sum + section.tokenEstimate, 0),
|
|
41
|
+
sections: compact.sections,
|
|
42
|
+
omitted: compact.omitted
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function addSection(sections, kind, content, sectionPath) {
|
|
46
|
+
sections.push({
|
|
47
|
+
kind,
|
|
48
|
+
...(sectionPath ? { path: sectionPath } : {}),
|
|
49
|
+
content,
|
|
50
|
+
tokenEstimate: estimateGlmTokens(content)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function enforceBudget(sections, omitted, maxTokens) {
|
|
54
|
+
const kept = [];
|
|
55
|
+
const nextOmitted = [...omitted];
|
|
56
|
+
let total = 0;
|
|
57
|
+
for (const section of sections) {
|
|
58
|
+
if (total + section.tokenEstimate <= maxTokens) {
|
|
59
|
+
kept.push(section);
|
|
60
|
+
total += section.tokenEstimate;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
nextOmitted.push({
|
|
64
|
+
kind: section.kind,
|
|
65
|
+
...(section.path ? { path: section.path } : {}),
|
|
66
|
+
reason: 'speed_context_token_budget'
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return { sections: kept, omitted: nextOmitted };
|
|
70
|
+
}
|
|
71
|
+
function digestJson(value) {
|
|
72
|
+
return crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
73
|
+
}
|
|
74
|
+
function trimToUtf8Bytes(text, maxBytes) {
|
|
75
|
+
if (Buffer.byteLength(text, 'utf8') <= maxBytes)
|
|
76
|
+
return text;
|
|
77
|
+
let end = Math.min(text.length, maxBytes);
|
|
78
|
+
while (end > 0 && Buffer.byteLength(text.slice(0, end), 'utf8') > maxBytes)
|
|
79
|
+
end -= 1;
|
|
80
|
+
return text.slice(0, end);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=glm-speed-context.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { parseGlmSpeedOutput } from './glm-speed-output-parser.js';
|
|
2
|
+
const FORBIDDEN_TOUCHED_PATH = /(^|\/)(\.github|dist|node_modules)(\/|$)/;
|
|
3
|
+
export function evaluateGlmSpeedGate(output) {
|
|
4
|
+
const started = Date.now();
|
|
5
|
+
const checks = [];
|
|
6
|
+
const parsed = parseGlmSpeedOutput(output);
|
|
7
|
+
checks.push(check('patch_parse', parsed.kind === 'patch', parsed.kind === 'patch' ? undefined : parsed.reason || parsed.kind));
|
|
8
|
+
const paths = parsed.kind === 'patch' ? touchedPaths(parsed.content) : [];
|
|
9
|
+
checks.push(check('touched_path_allowlist', paths.every((file) => !FORBIDDEN_TOUCHED_PATH.test(file)), paths.find((file) => FORBIDDEN_TOUCHED_PATH.test(file))));
|
|
10
|
+
checks.push(check('patch_apply_dry_run_ready', parsed.kind === 'patch' && /^diff --git /m.test(parsed.content), parsed.kind === 'patch' ? undefined : 'no_patch'));
|
|
11
|
+
const ok = checks.every((row) => row.ok);
|
|
12
|
+
return {
|
|
13
|
+
schema: 'sks.glm-speed-gate.v1',
|
|
14
|
+
ok,
|
|
15
|
+
gate_ms: Date.now() - started,
|
|
16
|
+
deterministic: true,
|
|
17
|
+
checks,
|
|
18
|
+
requiresDeepEscalation: !ok
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function touchedPaths(patch) {
|
|
22
|
+
const paths = [];
|
|
23
|
+
for (const line of patch.split(/\r?\n/)) {
|
|
24
|
+
const match = line.match(/^diff --git a\/(.+?) b\/(.+)$/);
|
|
25
|
+
if (match?.[1])
|
|
26
|
+
paths.push(match[1]);
|
|
27
|
+
if (match?.[2])
|
|
28
|
+
paths.push(match[2]);
|
|
29
|
+
}
|
|
30
|
+
return [...new Set(paths)];
|
|
31
|
+
}
|
|
32
|
+
function check(id, ok, reason) {
|
|
33
|
+
return {
|
|
34
|
+
id,
|
|
35
|
+
ok,
|
|
36
|
+
ms: 0,
|
|
37
|
+
...(reason ? { reason } : {})
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=glm-speed-gate.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const ENVELOPES = {
|
|
2
|
+
patch: ['<sks_patch>', '</sks_patch>'],
|
|
3
|
+
need_context: ['<sks_need_context>', '</sks_need_context>'],
|
|
4
|
+
blocked: ['<sks_blocked>', '</sks_blocked>']
|
|
5
|
+
};
|
|
6
|
+
export function parseGlmSpeedOutput(text) {
|
|
7
|
+
for (const kind of ['patch', 'need_context', 'blocked']) {
|
|
8
|
+
const extracted = extractEnvelope(text, ENVELOPES[kind][0], ENVELOPES[kind][1]);
|
|
9
|
+
if (extracted !== null) {
|
|
10
|
+
return {
|
|
11
|
+
kind,
|
|
12
|
+
content: extracted,
|
|
13
|
+
...(kind === 'need_context' ? { paths: parsePaths(extracted) } : {}),
|
|
14
|
+
...(kind === 'blocked' ? { reason: parseReason(extracted) } : {})
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const cleaned = text.trim();
|
|
19
|
+
return { kind: 'malformed', content: cleaned, reason: 'missing_glm_speed_output_envelope' };
|
|
20
|
+
}
|
|
21
|
+
function extractEnvelope(text, start, end) {
|
|
22
|
+
const startIndex = text.indexOf(start);
|
|
23
|
+
if (startIndex < 0)
|
|
24
|
+
return null;
|
|
25
|
+
const contentStart = startIndex + start.length;
|
|
26
|
+
const endIndex = text.indexOf(end, contentStart);
|
|
27
|
+
if (endIndex < 0)
|
|
28
|
+
return null;
|
|
29
|
+
return text.slice(contentStart, endIndex).trim();
|
|
30
|
+
}
|
|
31
|
+
function parsePaths(content) {
|
|
32
|
+
return content
|
|
33
|
+
.split(/\r?\n/)
|
|
34
|
+
.map((line) => line.match(/^\s*-\s*(.+?)\s*$/)?.[1])
|
|
35
|
+
.filter((value) => Boolean(value));
|
|
36
|
+
}
|
|
37
|
+
function parseReason(content) {
|
|
38
|
+
return content.match(/reason:\s*(.+)/i)?.[1]?.trim() || content.trim();
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=glm-speed-output-parser.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { SksLruCache } from '../../perf/lru-cache.js';
|
|
3
|
+
export function createGlmToolSchemaCache(maxEntries = 64) {
|
|
4
|
+
const cache = new SksLruCache(maxEntries);
|
|
5
|
+
return {
|
|
6
|
+
get(toolsetVersion) {
|
|
7
|
+
return cache.get(toolsetVersion);
|
|
8
|
+
},
|
|
9
|
+
set(toolsetVersion, tools) {
|
|
10
|
+
const entry = { key: toolsetVersion, tools, createdAt: Date.now() };
|
|
11
|
+
cache.set(toolsetVersion, entry);
|
|
12
|
+
return entry;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function digestToolset(tools) {
|
|
17
|
+
return crypto.createHash('sha256').update(JSON.stringify(tools)).digest('hex');
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=glm-tool-schema-cache.js.map
|
package/dist/core/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '4.0.
|
|
1
|
+
export const PACKAGE_VERSION = '4.0.5';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sneakoscope",
|
|
3
3
|
"displayName": "ㅅㅋㅅ",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.5",
|
|
5
5
|
"description": "Sneakoscope Codex: fast proof-first Codex trust layer with image-based Voxel TriWiki.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"homepage": "https://github.com/mandarange/Sneakoscope-Codex#readme",
|