sneakoscope 4.0.3 → 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.
Files changed (30) hide show
  1. package/README.md +9 -8
  2. package/crates/sks-core/Cargo.lock +1 -1
  3. package/crates/sks-core/Cargo.toml +1 -1
  4. package/crates/sks-core/src/main.rs +1 -1
  5. package/dist/bin/sks.js +1 -1
  6. package/dist/core/codex-app/glm-profile-schema.js +5 -1
  7. package/dist/core/commands/glm-command.js +20 -1
  8. package/dist/core/commands/mad-sks-command.js +174 -20
  9. package/dist/core/fsx.js +1 -1
  10. package/dist/core/perf/lru-cache.js +33 -0
  11. package/dist/core/providers/glm/glm-52-profile.js +14 -7
  12. package/dist/core/providers/glm/glm-52-request.js +40 -12
  13. package/dist/core/providers/glm/glm-52-response-guard.js +1 -2
  14. package/dist/core/providers/glm/glm-52-settings.js +50 -8
  15. package/dist/core/providers/glm/glm-bench.js +90 -0
  16. package/dist/core/providers/glm/glm-context-budget.js +15 -0
  17. package/dist/core/providers/glm/glm-context-cache.js +9 -0
  18. package/dist/core/providers/glm/glm-latency-trace.js +40 -0
  19. package/dist/core/providers/glm/glm-mad-launch.js +128 -0
  20. package/dist/core/providers/glm/glm-mad-mode.js +48 -20
  21. package/dist/core/providers/glm/glm-model-meta-cache.js +19 -0
  22. package/dist/core/providers/glm/glm-profile-resolver.js +104 -0
  23. package/dist/core/providers/glm/glm-reasoning-policy.js +15 -0
  24. package/dist/core/providers/glm/glm-request-cache.js +47 -0
  25. package/dist/core/providers/glm/glm-speed-context.js +82 -0
  26. package/dist/core/providers/glm/glm-speed-gate.js +40 -0
  27. package/dist/core/providers/glm/glm-speed-output-parser.js +40 -0
  28. package/dist/core/providers/glm/glm-tool-schema-cache.js +19 -0
  29. package/dist/core/version.js +1 -1
  30. package/package.json +1 -1
@@ -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
@@ -1,2 +1,2 @@
1
- export const PACKAGE_VERSION = '4.0.3';
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.3",
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",