@lornatang/dsh-caveman 0.1.9 → 0.1.10

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.
@@ -1,14 +1,14 @@
1
- # Merge this provider into the existing llm-pi-ai providers map.
2
- # Replace the model id with one available to the Anthropic credential.
3
- - id: llm-pi-ai
4
- config:
5
- providers:
6
- caveman-anthropic:
7
- displayName: Caveman Anthropic
8
- api: anthropic-messages
9
- baseURL: 'http://127.0.0.1:8787'
10
- apiKeyEnv: ANTHROPIC_API_KEY
11
- cacheRetention: short
12
- models:
13
- - id: claude-sonnet-4-5
14
- name: Claude Sonnet 4.5
1
+ # Merge this provider into the existing llm-pi-ai providers map.
2
+ # Replace the model id with one available to the Anthropic credential.
3
+ - id: llm-pi-ai
4
+ config:
5
+ providers:
6
+ caveman-anthropic:
7
+ displayName: Caveman Anthropic
8
+ api: anthropic-messages
9
+ baseURL: 'http://127.0.0.1:8787'
10
+ apiKeyEnv: ANTHROPIC_API_KEY
11
+ cacheRetention: short
12
+ models:
13
+ - id: claude-sonnet-4-5
14
+ name: Claude Sonnet 4.5
@@ -1,15 +1,15 @@
1
- # Example only: merge this provider with the existing llm-pi-ai providers.
2
- # Replacing the providers map would remove the other configured routes.
3
- - id: llm-pi-ai
4
- config:
5
- providers:
6
- caveman-auto:
7
- displayName: Caveman Auto
8
- api: openai-completions
9
- baseURL: 'http://127.0.0.1:8787/v1'
10
- apiKeyEnv: OPENAI_API_KEY
11
- headers:
12
- x-cave-agent: dsh
13
- models:
14
- - id: caveman-auto
15
- name: Caveman Auto
1
+ # Example only: merge this provider with the existing llm-pi-ai providers.
2
+ # Replacing the providers map would remove the other configured routes.
3
+ - id: llm-pi-ai
4
+ config:
5
+ providers:
6
+ caveman-auto:
7
+ displayName: Caveman Auto
8
+ api: openai-completions
9
+ baseURL: 'http://127.0.0.1:8787/v1'
10
+ apiKeyEnv: OPENAI_API_KEY
11
+ headers:
12
+ x-cave-agent: dsh
13
+ models:
14
+ - id: caveman-auto
15
+ name: Caveman Auto
package/lib/cavecrew.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { readFile } from 'node:fs/promises';
2
- import { normalize } from 'node:path';
3
2
  import z from '@deepseek-ai/schemastery';
4
3
  import { registerCavecrewGit } from './cavecrew-git.js';
5
4
  export const name = 'cavecrew';
@@ -7,6 +6,57 @@ export const inject = ['tools', 'systemPrompt', 'llm'];
7
6
  export const Config = z.object({
8
7
  role: z.union([z.const('investigator'), z.const('builder'), z.const('reviewer')]).required(),
9
8
  });
9
+ function limitBuilderEdits(ctx) {
10
+ const byAgent = new WeakMap();
11
+ const active = new WeakMap();
12
+ ctx.on('tools/execute', async (exec, next) => {
13
+ if (exec.name !== 'edit' || !exec.agent)
14
+ return next();
15
+ const targets = byAgent.get(exec.agent) ?? new Map();
16
+ byAgent.set(exec.agent, targets);
17
+ const attempt = { targets };
18
+ active.set(exec, attempt);
19
+ try {
20
+ return await next();
21
+ }
22
+ finally {
23
+ active.delete(exec);
24
+ const reservation = attempt.reservation;
25
+ if (reservation) {
26
+ reservation.state.pending -= 1;
27
+ if (!reservation.state.committed && reservation.state.pending === 0)
28
+ targets.delete(reservation.key);
29
+ }
30
+ }
31
+ });
32
+ // The filesystem tool supplies the resolved target that it will actually edit.
33
+ ctx.on('fs/edit-intent', async (target, actor, next) => {
34
+ const attempt = actor ? active.get(actor) : undefined;
35
+ if (!attempt)
36
+ return next();
37
+ const key = target.targetKey;
38
+ if (attempt.reservation) {
39
+ if (attempt.reservation.key !== key)
40
+ throw new Error('Cavecrew edit cannot change its resolved target.');
41
+ return next();
42
+ }
43
+ let state = attempt.targets.get(key);
44
+ if (!state) {
45
+ if (attempt.targets.size >= 2)
46
+ throw new Error('Cavecrew builder is limited to two file paths.');
47
+ state = { pending: 0, committed: false };
48
+ attempt.targets.set(key, state);
49
+ }
50
+ state.pending += 1;
51
+ attempt.reservation = { key, state };
52
+ return next();
53
+ }, { prepend: true });
54
+ ctx.on('fs/observed', (target, observation, actor) => {
55
+ const reservation = actor ? active.get(actor)?.reservation : undefined;
56
+ if (reservation?.key === target.targetKey && observation.kind === 'present')
57
+ reservation.state.committed = true;
58
+ }, { prepend: true });
59
+ }
10
60
  /** Install one original Cavecrew persona and keep its agent's tools bounded. */
11
61
  export async function apply(ctx, config) {
12
62
  const original = await readFile(new URL(`../vendor/caveman/agents/cavecrew-${config.role}.md`, import.meta.url), 'utf8');
@@ -32,11 +82,6 @@ export async function apply(ctx, config) {
32
82
  });
33
83
  }
34
84
  const permitted = new Set(allowed);
35
- const edited = new WeakMap();
36
- const editKey = (value) => {
37
- const normalized = normalize(value);
38
- return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
39
- };
40
85
  ctx.tools.guard(exec => {
41
86
  if (!permitted.has(exec.name))
42
87
  return `Cavecrew ${config.role} does not permit ${exec.name}.`;
@@ -46,28 +91,10 @@ export async function apply(ctx, config) {
46
91
  !('file_path' in exec.arguments) || typeof exec.arguments.file_path !== 'string' || !exec.arguments.file_path.trim()) {
47
92
  return 'Cavecrew builder requires an existing file path.';
48
93
  }
49
- const path = editKey(exec.arguments.file_path);
50
- const paths = edited.get(exec.agent) ?? new Set();
51
- if (!paths.has(path)) {
52
- if (paths.size >= 2)
53
- return 'Cavecrew builder is limited to two file paths.';
54
- paths.add(path);
55
- edited.set(exec.agent, paths);
56
- }
57
94
  return undefined;
58
95
  });
59
- if (config.role === 'builder') {
60
- // The guard runs before the edit body, so refund the budget when the edit fails.
61
- ctx.on('tools/execute', async (exec, next) => {
62
- const result = await next();
63
- if (exec.name !== 'edit' || !exec.agent || !result.isError ||
64
- typeof exec.arguments !== 'object' || exec.arguments === null ||
65
- !('file_path' in exec.arguments) || typeof exec.arguments.file_path !== 'string')
66
- return result;
67
- edited.get(exec.agent)?.delete(editKey(exec.arguments.file_path));
68
- return result;
69
- });
70
- }
96
+ if (config.role === 'builder')
97
+ limitBuilderEdits(ctx);
71
98
  ctx.on('agent/created', async ({ agent }) => {
72
99
  const available = allowed.filter(tool => ctx.tools.get(tool, agent) !== undefined);
73
100
  agent.ctx.tools.restrict({ allow: available });
package/lib/native.js CHANGED
@@ -3,7 +3,7 @@ import { constants } from 'node:fs';
3
3
  import { lstat, open, realpath, stat } from 'node:fs/promises';
4
4
  import { connect } from 'node:net';
5
5
  import { homedir } from 'node:os';
6
- import { join, resolve, win32 } from 'node:path';
6
+ import { join, resolve } from 'node:path';
7
7
  import { setTimeout as delay } from 'node:timers/promises';
8
8
  import { isDeepStrictEqual } from 'node:util';
9
9
  import { createUserMessage } from '@deepseek-ai/dsh-llm';
@@ -49,14 +49,11 @@ export function nativePrompt(prompt) {
49
49
  const bytes = Buffer.from(prompt, 'utf8');
50
50
  return { prompt: { bytes: bytes.length, sha256: `sha256:${createHash('sha256').update(bytes).digest('hex')}` }, task_profile: { type, terms: [...seen], continuation } };
51
51
  }
52
- /** Name the same per-install socket as the local runtime. */
52
+ /** Return the supported local socket endpoint, if available on this platform. */
53
53
  export function nativeSocketPath(home, platform = process.platform) {
54
- if (platform !== 'win32')
55
- return join(home, 'run', 'native.sock');
56
- let folded = '';
57
- for (const char of win32.resolve(home))
58
- folded += String.fromCodePoint(char.toLowerCase().codePointAt(0));
59
- return `\\\\.\\pipe\\caveman-native-${createHash('sha256').update(folded).digest('hex').slice(0, 16)}`;
54
+ // The current Windows runtime has no pipe peer proof, and its HTTP health
55
+ // check only verifies the HTTP listener. Keep native events local to DSH.
56
+ return platform === 'win32' ? undefined : join(home, 'run', 'native.sock');
60
57
  }
61
58
  function validResponse(value) {
62
59
  if (!value || typeof value !== 'object' || Array.isArray(value))
@@ -78,8 +75,6 @@ function validResponse(value) {
78
75
  }
79
76
  /** Refuse a replaced socket path before sending prompt terms or tool data over it. */
80
77
  async function socketTrust(path) {
81
- if (process.platform === 'win32')
82
- return 'trusted';
83
78
  try {
84
79
  const info = await lstat(path);
85
80
  if (!info.isSocket())
@@ -98,7 +93,7 @@ export async function nativeCall(home, request, signal) {
98
93
  if (signal?.aborted)
99
94
  return undefined;
100
95
  const socketPath = nativeSocketPath(home);
101
- if (await socketTrust(socketPath) === 'untrusted')
96
+ if (!socketPath || await socketTrust(socketPath) === 'untrusted')
102
97
  return undefined;
103
98
  const payload = Buffer.from(JSON.stringify(request) + '\n');
104
99
  if (payload.length > 2 * 1024 * 1024)
@@ -223,11 +218,13 @@ async function runtimeInstance(endpoint, home, signal) {
223
218
  }
224
219
  /** Add dynamic native task context when the verified local runtime is running. */
225
220
  export function registerNative(ctx, endpoint, policy) {
221
+ const home = process.env.CAVEMAN_HOME ?? join(homedir(), '.caveman');
222
+ if (!nativeSocketPath(home))
223
+ return;
226
224
  const sessions = new WeakMap();
227
225
  const owners = new WeakMap();
228
226
  const selections = new WeakMap();
229
227
  const pending = new Set();
230
- const home = process.env.CAVEMAN_HOME ?? join(homedir(), '.caveman');
231
228
  ctx.on('system-prompt/assemble', async (_assembly, context, next) => {
232
229
  const result = await next();
233
230
  if (context.agent && context.toolSet)
@@ -31,8 +31,8 @@ export declare function nativePrompt(prompt: string): {
31
31
  continuation: boolean;
32
32
  };
33
33
  };
34
- /** Name the same per-install socket as the local runtime. */
35
- export declare function nativeSocketPath(home: string, platform?: NodeJS.Platform): string;
34
+ /** Return the supported local socket endpoint, if available on this platform. */
35
+ export declare function nativeSocketPath(home: string, platform?: NodeJS.Platform): string | undefined;
36
36
  export declare function nativeCall(home: string, request: object, signal?: AbortSignal): Promise<NativeResponse | undefined>;
37
37
  /** Add dynamic native task context when the verified local runtime is running. */
38
38
  export declare function registerNative(ctx: Context, endpoint: string, policy: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lornatang/dsh-caveman",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Caveman integration for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -120,11 +120,12 @@
120
120
  },
121
121
  "repository": {
122
122
  "type": "git",
123
- "url": "git+https://github.com/Lornatang/dsh-caveman.git"
123
+ "url": "git+https://github.com/Lornatang/dsh-plugin.git",
124
+ "directory": "packages/workflow/dsh-caveman"
124
125
  },
125
- "homepage": "https://github.com/Lornatang/dsh-caveman#readme",
126
+ "homepage": "https://github.com/Lornatang/dsh-plugin/tree/main/packages/workflow/dsh-caveman#readme",
126
127
  "bugs": {
127
- "url": "https://github.com/Lornatang/dsh-caveman/issues"
128
+ "url": "https://github.com/Lornatang/dsh-plugin/issues"
128
129
  },
129
130
  "publishConfig": {
130
131
  "access": "public",
@@ -1,54 +1,54 @@
1
- # Cavecrew agent presets and their in-process delegation tools. The read-only
2
- # roles use a read-only Git tool instead of a shell.
3
- - insert:
4
- - id: preset-cavecrew-investigator
5
- name: '@deepseek-ai/dsh-agent-preset'
6
- config:
7
- id: cavecrew-investigator
8
- name: Cavecrew Investigator
9
- plugins:
10
- - id: cavecrew
11
- name: '@lornatang/dsh-caveman/cavecrew'
12
- config: { role: investigator }
13
- - id: tool-fs
14
- name: '@deepseek-ai/dsh-tool-fs'
15
- config: { readImage: false, write: false, edit: false, applyPatch: false }
16
- - id: tool-fs-search
17
- name: '@deepseek-ai/dsh-tool-fs-search'
18
- config: { sampleOverCapGlobResults: false }
19
- - id: preset-cavecrew-builder
20
- name: '@deepseek-ai/dsh-agent-preset'
21
- config:
22
- id: cavecrew-builder
23
- name: Cavecrew Builder
24
- plugins:
25
- - id: cavecrew
26
- name: '@lornatang/dsh-caveman/cavecrew'
27
- config: { role: builder }
28
- - id: tool-fs
29
- name: '@deepseek-ai/dsh-tool-fs'
30
- config: { readImage: false, write: false, applyPatch: false }
31
- - id: preset-cavecrew-reviewer
32
- name: '@deepseek-ai/dsh-agent-preset'
33
- config:
34
- id: cavecrew-reviewer
35
- name: Cavecrew Reviewer
36
- plugins:
37
- - id: cavecrew
38
- name: '@lornatang/dsh-caveman/cavecrew'
39
- config: { role: reviewer }
40
- - id: tool-fs
41
- name: '@deepseek-ai/dsh-tool-fs'
42
- config: { readImage: false, write: false, edit: false, applyPatch: false }
43
- - id: tool-fs-search
44
- name: '@deepseek-ai/dsh-tool-fs-search'
45
- config: { sampleOverCapGlobResults: false }
46
- - id: tool-cavecrew-investigator
47
- name: '@deepseek-ai/dsh-tool-subagent'
48
- config: { provider: spawn, toolName: cavecrew-investigator, agentPreset: cavecrew-investigator }
49
- - id: tool-cavecrew-builder
50
- name: '@deepseek-ai/dsh-tool-subagent'
51
- config: { provider: spawn, toolName: cavecrew-builder, agentPreset: cavecrew-builder }
52
- - id: tool-cavecrew-reviewer
53
- name: '@deepseek-ai/dsh-tool-subagent'
54
- config: { provider: spawn, toolName: cavecrew-reviewer, agentPreset: cavecrew-reviewer }
1
+ # Cavecrew agent presets and their in-process delegation tools. The read-only
2
+ # roles use a read-only Git tool instead of a shell.
3
+ - insert:
4
+ - id: preset-cavecrew-investigator
5
+ name: '@deepseek-ai/dsh-agent-preset'
6
+ config:
7
+ id: cavecrew-investigator
8
+ name: Cavecrew Investigator
9
+ plugins:
10
+ - id: cavecrew
11
+ name: '@lornatang/dsh-caveman/cavecrew'
12
+ config: { role: investigator }
13
+ - id: tool-fs
14
+ name: '@deepseek-ai/dsh-tool-fs'
15
+ config: { readImage: false, write: false, edit: false, applyPatch: false }
16
+ - id: tool-fs-search
17
+ name: '@deepseek-ai/dsh-tool-fs-search'
18
+ config: { sampleOverCapGlobResults: false }
19
+ - id: preset-cavecrew-builder
20
+ name: '@deepseek-ai/dsh-agent-preset'
21
+ config:
22
+ id: cavecrew-builder
23
+ name: Cavecrew Builder
24
+ plugins:
25
+ - id: cavecrew
26
+ name: '@lornatang/dsh-caveman/cavecrew'
27
+ config: { role: builder }
28
+ - id: tool-fs
29
+ name: '@deepseek-ai/dsh-tool-fs'
30
+ config: { readImage: false, write: false, applyPatch: false }
31
+ - id: preset-cavecrew-reviewer
32
+ name: '@deepseek-ai/dsh-agent-preset'
33
+ config:
34
+ id: cavecrew-reviewer
35
+ name: Cavecrew Reviewer
36
+ plugins:
37
+ - id: cavecrew
38
+ name: '@lornatang/dsh-caveman/cavecrew'
39
+ config: { role: reviewer }
40
+ - id: tool-fs
41
+ name: '@deepseek-ai/dsh-tool-fs'
42
+ config: { readImage: false, write: false, edit: false, applyPatch: false }
43
+ - id: tool-fs-search
44
+ name: '@deepseek-ai/dsh-tool-fs-search'
45
+ config: { sampleOverCapGlobResults: false }
46
+ - id: tool-cavecrew-investigator
47
+ name: '@deepseek-ai/dsh-tool-subagent'
48
+ config: { provider: spawn, toolName: cavecrew-investigator, agentPreset: cavecrew-investigator }
49
+ - id: tool-cavecrew-builder
50
+ name: '@deepseek-ai/dsh-tool-subagent'
51
+ config: { provider: spawn, toolName: cavecrew-builder, agentPreset: cavecrew-builder }
52
+ - id: tool-cavecrew-reviewer
53
+ name: '@deepseek-ai/dsh-tool-subagent'
54
+ config: { provider: spawn, toolName: cavecrew-reviewer, agentPreset: cavecrew-reviewer }
@@ -1,79 +1,79 @@
1
- import { performance } from 'node:perf_hooks'
2
- import { resolve } from 'node:path'
3
- import { SessionModeTracker, resolveMode } from '../lib/mode.js'
4
- import { createSkillProvider } from '../lib/skills.js'
5
- import { CompressionHistoryIndex } from '../lib/compression.js'
6
-
7
- function median(values) {
8
- const sorted = [...values].sort((a, b) => a - b)
9
- return sorted[Math.floor(sorted.length / 2)]
10
- }
11
-
12
- const events = Array.from({ length: 1000 }, (_, index) => ({
13
- type: 'user/message', data: {
14
- source: { kind: 'user' },
15
- content: [{ type: 'text', text: index % 150 === 0 ? '/caveman ultra' : 'Inspect the current code and report the results.' }],
16
- },
17
- }))
18
- const session = {
19
- get seq() { return events.length },
20
- snapshotEvents(from = 0, to = events.length) { return events.slice(from, to) },
21
- }
22
- const pending = [{ source: { kind: 'user' }, content: [{ type: 'text', text: 'continue' }] }]
23
- const tracker = new SessionModeTracker()
24
- tracker.resolve('manual', session, pending)
25
- const full = []
26
- const incremental = []
27
- for (let index = 0; index < 101; index++) {
28
- events.push({ type: 'turn/start', data: {} })
29
- let start = performance.now()
30
- const expected = resolveMode('manual', events, pending)
31
- full.push(performance.now() - start)
32
- start = performance.now()
33
- const actual = tracker.resolve('manual', session, pending)
34
- incremental.push(performance.now() - start)
35
- if (actual.mode !== expected.mode || actual.action !== expected.action) throw new Error('mode results differ')
36
- }
37
- const provider = createSkillProvider(resolve('vendor/caveman/skills'))
38
- const discovery = []
39
- for (let index = 0; index < 31; index++) {
40
- const start = performance.now()
41
- const result = await provider.list({})
42
- if (!result.complete || result.candidates.length !== 22) throw new Error('skill catalog is incomplete')
43
- discovery.push(performance.now() - start)
44
- }
45
- const historyEvents = Array.from({ length: 5000 }, (_, index) => index % 2 === 0
46
- ? { type: 'assistant/message', data: { message: { content: [{ type: 'tool-call', id: `call-${index}`, name: 'read' }] } } }
47
- : { type: 'tool/result', data: { message: { content: [{ type: 'text', text: 'ordinary result' }] } } })
48
- const historySession = {
49
- get seq() { return historyEvents.length },
50
- snapshotEvents(from = 0, to = historyEvents.length) { return historyEvents.slice(from, to) },
51
- eventAt() { return undefined },
52
- }
53
- const history = new CompressionHistoryIndex()
54
- history.read(historySession)
55
- const fullHistory = []
56
- const incrementalHistory = []
57
- for (let index = 0; index < 101; index++) {
58
- historyEvents.push({ type: 'turn/start', data: {} })
59
- let start = performance.now()
60
- const hasMarker = historySession.snapshotEvents().some(event => event.type === 'tool/result' &&
61
- event.data.message.content.some(block => block.type === 'text' && block.text.includes('[caveman: shortened; exact original via caveman_retrieve handle=')))
62
- const names = new Map()
63
- for (const event of historySession.snapshotEvents()) {
64
- if (event.type === 'assistant/message') for (const block of event.data.message.content) {
65
- if (block.type === 'tool-call' && !names.has(block.id)) names.set(block.id, block.name)
66
- }
67
- }
68
- fullHistory.push(performance.now() - start)
69
- start = performance.now()
70
- const actual = history.read(historySession)
71
- history.read(historySession)
72
- incrementalHistory.push(performance.now() - start)
73
- if (actual.hasMarker !== hasMarker || actual.toolNames.size !== names.size) throw new Error('compression history differs')
74
- }
75
- console.log(JSON.stringify({
76
- mode: { initialMessages: 1000, runs: full.length, fullReplayMedianMs: median(full), incrementalMedianMs: median(incremental) },
77
- skills: { count: 22, runs: discovery.length, discoveryMedianMs: median(discovery) },
78
- compressionHistory: { initialEvents: 5000, runs: fullHistory.length, fullScanMedianMs: median(fullHistory), incrementalMedianMs: median(incrementalHistory) },
79
- }, null, 2))
1
+ import { performance } from 'node:perf_hooks'
2
+ import { resolve } from 'node:path'
3
+ import { SessionModeTracker, resolveMode } from '../lib/mode.js'
4
+ import { createSkillProvider } from '../lib/skills.js'
5
+ import { CompressionHistoryIndex } from '../lib/compression.js'
6
+
7
+ function median(values) {
8
+ const sorted = [...values].sort((a, b) => a - b)
9
+ return sorted[Math.floor(sorted.length / 2)]
10
+ }
11
+
12
+ const events = Array.from({ length: 1000 }, (_, index) => ({
13
+ type: 'user/message', data: {
14
+ source: { kind: 'user' },
15
+ content: [{ type: 'text', text: index % 150 === 0 ? '/caveman ultra' : 'Inspect the current code and report the results.' }],
16
+ },
17
+ }))
18
+ const session = {
19
+ get seq() { return events.length },
20
+ snapshotEvents(from = 0, to = events.length) { return events.slice(from, to) },
21
+ }
22
+ const pending = [{ source: { kind: 'user' }, content: [{ type: 'text', text: 'continue' }] }]
23
+ const tracker = new SessionModeTracker()
24
+ tracker.resolve('manual', session, pending)
25
+ const full = []
26
+ const incremental = []
27
+ for (let index = 0; index < 101; index++) {
28
+ events.push({ type: 'turn/start', data: {} })
29
+ let start = performance.now()
30
+ const expected = resolveMode('manual', events, pending)
31
+ full.push(performance.now() - start)
32
+ start = performance.now()
33
+ const actual = tracker.resolve('manual', session, pending)
34
+ incremental.push(performance.now() - start)
35
+ if (actual.mode !== expected.mode || actual.action !== expected.action) throw new Error('mode results differ')
36
+ }
37
+ const provider = createSkillProvider(resolve('vendor/caveman/skills'))
38
+ const discovery = []
39
+ for (let index = 0; index < 31; index++) {
40
+ const start = performance.now()
41
+ const result = await provider.list({})
42
+ if (!result.complete || result.candidates.length !== 22) throw new Error('skill catalog is incomplete')
43
+ discovery.push(performance.now() - start)
44
+ }
45
+ const historyEvents = Array.from({ length: 5000 }, (_, index) => index % 2 === 0
46
+ ? { type: 'assistant/message', data: { message: { content: [{ type: 'tool-call', id: `call-${index}`, name: 'read' }] } } }
47
+ : { type: 'tool/result', data: { message: { content: [{ type: 'text', text: 'ordinary result' }] } } })
48
+ const historySession = {
49
+ get seq() { return historyEvents.length },
50
+ snapshotEvents(from = 0, to = historyEvents.length) { return historyEvents.slice(from, to) },
51
+ eventAt() { return undefined },
52
+ }
53
+ const history = new CompressionHistoryIndex()
54
+ history.read(historySession)
55
+ const fullHistory = []
56
+ const incrementalHistory = []
57
+ for (let index = 0; index < 101; index++) {
58
+ historyEvents.push({ type: 'turn/start', data: {} })
59
+ let start = performance.now()
60
+ const hasMarker = historySession.snapshotEvents().some(event => event.type === 'tool/result' &&
61
+ event.data.message.content.some(block => block.type === 'text' && block.text.includes('[caveman: shortened; exact original via caveman_retrieve handle=')))
62
+ const names = new Map()
63
+ for (const event of historySession.snapshotEvents()) {
64
+ if (event.type === 'assistant/message') for (const block of event.data.message.content) {
65
+ if (block.type === 'tool-call' && !names.has(block.id)) names.set(block.id, block.name)
66
+ }
67
+ }
68
+ fullHistory.push(performance.now() - start)
69
+ start = performance.now()
70
+ const actual = history.read(historySession)
71
+ history.read(historySession)
72
+ incrementalHistory.push(performance.now() - start)
73
+ if (actual.hasMarker !== hasMarker || actual.toolNames.size !== names.size) throw new Error('compression history differs')
74
+ }
75
+ console.log(JSON.stringify({
76
+ mode: { initialMessages: 1000, runs: full.length, fullReplayMedianMs: median(full), incrementalMedianMs: median(incremental) },
77
+ skills: { count: 22, runs: discovery.length, discoveryMedianMs: median(discovery) },
78
+ compressionHistory: { initialEvents: 5000, runs: fullHistory.length, fullScanMedianMs: median(fullHistory), incrementalMedianMs: median(incrementalHistory) },
79
+ }, null, 2))
@@ -1,30 +1,30 @@
1
- #!/usr/bin/env node
2
- import { spawn } from 'node:child_process'
3
- import { constants } from 'node:os'
4
- import { createRequire } from 'node:module'
5
- import { dirname, join } from 'node:path'
6
-
7
- const require = createRequire(import.meta.url)
8
- const cli = join(dirname(require.resolve('@caveman-ai/cli/package.json')), 'dist', 'index.js')
9
- const args = process.argv.slice(2)
10
- let learnBinary
11
- if (args[0] === 'learn' && !['--help', '-h', 'help'].includes(args[1])) {
12
- try { learnBinary = await (await import('./learn-binary.mjs')).resolveLearnBinary() }
13
- catch (error) { console.error(`dsh-caveman: ${error.message}`); process.exit(1) }
14
- }
15
- const direct = learnBinary && args[1] === 'locate'
16
- const child = spawn(direct ? learnBinary : process.execPath, direct ? args : [cli, ...args], {
17
- stdio: 'inherit', windowsHide: true,
18
- env: learnBinary ? { ...process.env, CAVEMAN_PROXY_BIN: learnBinary } : process.env,
19
- })
20
-
21
- for (const signal of ['SIGINT', 'SIGTERM']) {
22
- process.on(signal, () => { if (child.exitCode === null && child.signalCode === null) child.kill(signal) })
23
- }
24
- child.once('error', error => {
25
- console.error(`dsh-caveman: could not start the CLI: ${error.message}`)
26
- process.exitCode = 1
27
- })
28
- child.once('exit', (code, signal) => {
29
- process.exitCode = code ?? (signal ? 128 + (constants.signals[signal] ?? 0) : 1)
30
- })
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process'
3
+ import { constants } from 'node:os'
4
+ import { createRequire } from 'node:module'
5
+ import { dirname, join } from 'node:path'
6
+
7
+ const require = createRequire(import.meta.url)
8
+ const cli = join(dirname(require.resolve('@caveman-ai/cli/package.json')), 'dist', 'index.js')
9
+ const args = process.argv.slice(2)
10
+ let learnBinary
11
+ if (args[0] === 'learn' && !['--help', '-h', 'help'].includes(args[1])) {
12
+ try { learnBinary = await (await import('./learn-binary.mjs')).resolveLearnBinary() }
13
+ catch (error) { console.error(`dsh-caveman: ${error.message}`); process.exit(1) }
14
+ }
15
+ const direct = learnBinary && args[1] === 'locate'
16
+ const child = spawn(direct ? learnBinary : process.execPath, direct ? args : [cli, ...args], {
17
+ stdio: 'inherit', windowsHide: true,
18
+ env: learnBinary ? { ...process.env, CAVEMAN_PROXY_BIN: learnBinary } : process.env,
19
+ })
20
+
21
+ for (const signal of ['SIGINT', 'SIGTERM']) {
22
+ process.on(signal, () => { if (child.exitCode === null && child.signalCode === null) child.kill(signal) })
23
+ }
24
+ child.once('error', error => {
25
+ console.error(`dsh-caveman: could not start the CLI: ${error.message}`)
26
+ process.exitCode = 1
27
+ })
28
+ child.once('exit', (code, signal) => {
29
+ process.exitCode = code ?? (signal ? 128 + (constants.signals[signal] ?? 0) : 1)
30
+ })