@lornatang/dsh-caveman 0.1.10 → 0.1.12

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.zh.md CHANGED
@@ -84,6 +84,7 @@ bundle 自带 `caveman` 行。在 profile 的 `cordis.patch.yml` 中添加覆盖
84
84
  | `browseBinary` | 自动查找 | 覆盖 `caveman-browse` 的绝对路径;需要 DSH MCP manager。 |
85
85
  | `mcpBinary` | 自动查找 | 覆盖 `caveman-mcp` 的绝对路径;需要 DSH MCP manager。 |
86
86
  | `memoryBinary` | 自动发现 | 覆盖 `cavemem` 的绝对路径;启用本地记忆工具。 |
87
+ | `codeMode` | `false` | 使用指定的配置文件和工作区启用 Caveman 4.2.0 的 Code-Mode MCP 网关。 |
87
88
 
88
89
  ### 回答模式与用量
89
90
 
@@ -91,6 +92,8 @@ bundle 自带 `caveman` 行。在 profile 的 `cordis.patch.yml` 中添加覆盖
91
92
 
92
93
  `defaultMode` 可设为 `caveman`、`ultracave`、`megacave`、`manual` 或 `off`。profile 的显式配置优先;否则依次检查 `CAVEMAN_DEFAULT_MODE`、项目配置和用户配置,均未设置时使用 `caveman`。
93
94
 
95
+ 设置 `CAVEMAN_REINFORCE=0`,或在 Caveman 配置中设置 `"reinforce": false`,可关闭每轮风格提醒。首次规则和切换模式时的规则仍会传给模型。
96
+
94
97
  output 模块和 Core 启用时,原生编码规则会加入系统提示词。本地运行时启动后,还会提供任务规则、衔接压缩前后的状态,并在文件确定未变化时提示复用已有观察;只有恢复 MCP 工具可用时才会展示恢复引用。设置 `CAVEMAN_CORE=off`、使用 record 模式或 `record-only` 原生 profile 可关闭活动规则;更改后重启 DSH。`core-lean-build` profile 会额外加入 lean-build 规则。
95
98
 
96
99
  Windows 上,DSH 会暂停原生事件钩子,直到本地运行时能够证明其管道身份。动态任务规则、原生压缩状态和文件观察复用依赖这些钩子。Windows 上可通过 HTTP middleware 使用压缩,也可使用静态编码规则。
@@ -136,6 +139,18 @@ Anthropic API 请求可将 [examples/caveman-anthropic.patch.yml](examples/cavem
136
139
 
137
140
  ### MCP、Blocks 和 Browse
138
141
 
142
+ 安装 Caveman 4.2.0 或更新的运行组件后,可在 DSH profile patch 中启用 Code-Mode:
143
+
144
+ ```yaml
145
+ - id: caveman
146
+ config:
147
+ codeMode:
148
+ config: /absolute/path/to/servers.json
149
+ workspace: /absolute/path/to/workspace
150
+ ```
151
+
152
+ 配置文件使用上游 `mcpServers` JSON 格式。填写 `{"mcpServers":{}}` 时只使用网关内置工具。DSH 以 `mcp__caveman_codemode__*` 注册网关,网关加载显式配置的 MCP 服务,并将只读执行与修改操作分配给不同工具。
153
+
139
154
  安装 `caveman-mcp` 后,DSH MCP manager 会提供 `mcp__caveman__*` 工具:`caveman_compress`、`caveman_retrieve`、`caveman_stats`、`caveman_toon_encode` 和 `caveman_toon_decode`。服务使用本地 Caveman 恢复存储保存句柄。设置 `CAVEMAN_MCP=off` 可关闭自动注册。
140
155
 
141
156
  安装 `cavemem` 后,MCP manager 会提供 `mcp__cavemem__*` 工具,用于记住、检索、修订、查看和删除本地事实。`cavemem_recover` 可取回检索句柄对应的完整原文,需要 DSH subprocess 和 working-directory 服务。记忆保存在本地 Caveman 目录。
package/cordis.patch.yml CHANGED
@@ -1,3 +1,3 @@
1
- - insert:
2
- - id: caveman
3
- name: '@lornatang/dsh-caveman'
1
+ - insert:
2
+ - id: caveman
3
+ name: '@lornatang/dsh-caveman'
@@ -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
@@ -36,7 +36,7 @@ function textBlocks(event) {
36
36
  return event.data.message.content.flatMap((block, index) => block.type === 'text' ? [{ index, text: block.text }] : []);
37
37
  }
38
38
  export function isManagedTool(name) {
39
- return name === 'caveman_retrieve' || name === 'cavemem_recover' || name.startsWith('mcp__caveman__') || name.startsWith('mcp__caveman_browse__') || name.startsWith('mcp__cavemem__') ||
39
+ return name === 'caveman_retrieve' || name === 'cavemem_recover' || name.startsWith('mcp__caveman__') || name.startsWith('mcp__caveman_browse__') || name.startsWith('mcp__caveman_codemode__') || name.startsWith('mcp__cavemem__') ||
40
40
  /^mcp__.+__(?:caveman_retrieve|browser_recover)$/u.test(name);
41
41
  }
42
42
  const MAX_ORIGINAL_ENTRIES = 64;
package/lib/index.js CHANGED
@@ -1,9 +1,10 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { readFileSync, statSync } from 'node:fs';
2
+ import { isAbsolute } from 'node:path';
2
3
  import { fileURLToPath } from 'node:url';
3
4
  import z from '@deepseek-ai/schemastery';
4
5
  import { createUserMessage } from '@deepseek-ai/dsh-llm';
5
6
  import { createSkillProvider } from './skills.js';
6
- import { defaultModeFor, SessionModeTracker } from './mode.js';
7
+ import { defaultModeFor, getReinforce, SessionModeTracker } from './mode.js';
7
8
  import { registerCompression } from './compression.js';
8
9
  import { registerBlocks } from './blocks.js';
9
10
  import { statsReport } from './stats.js';
@@ -23,6 +24,7 @@ export const Config = z.object({
23
24
  browseBinary: z.string().min(1),
24
25
  mcpBinary: z.string().min(1),
25
26
  memoryBinary: z.string().min(1),
27
+ codeMode: z.union([z.const(false), z.object({ config: z.string().required(), workspace: z.string().required() })]).default(false),
26
28
  });
27
29
  /** Register skills and reinforce the selected mode per session. */
28
30
  export function apply(ctx, config = {}) {
@@ -64,6 +66,18 @@ export function apply(ctx, config = {}) {
64
66
  ctx.inject(['subprocess', 'workingDirectory'], scoped => registerMemoryRecovery(scoped, memory));
65
67
  const servers = [{ name: 'caveman', binary: mcp, args: [] }, { name: 'caveman_browse', binary: browse, args: [] }, { name: 'cavemem', binary: memory, args: ['mcp'] }]
66
68
  .filter((server) => server.binary !== undefined);
69
+ if (settings.mcp && config.codeMode) {
70
+ if (!mcp)
71
+ throw new Error('dsh-caveman: Code-Mode requires the Caveman 4.2.0 or newer MCP binary');
72
+ const { config: serversFile, workspace } = config.codeMode;
73
+ if (!isAbsolute(serversFile) || !statSync(serversFile, { throwIfNoEntry: false })?.isFile()) {
74
+ throw new Error('dsh-caveman: codeMode.config must be an absolute path to an MCP configuration file');
75
+ }
76
+ if (!isAbsolute(workspace) || !statSync(workspace, { throwIfNoEntry: false })?.isDirectory()) {
77
+ throw new Error('dsh-caveman: codeMode.workspace must be an absolute path to a directory');
78
+ }
79
+ servers.push({ name: 'caveman_codemode', binary: mcp, args: ['codemode', '--config', serversFile, '--workspace', workspace] });
80
+ }
67
81
  if (servers.length) {
68
82
  ctx.inject(['mcpManager'], scoped => {
69
83
  for (const server of servers) {
@@ -101,6 +115,8 @@ export function apply(ctx, config = {}) {
101
115
  const selected = modes.resolve(defaultModeFor(config.defaultMode, cwd), agent.session, directMessages);
102
116
  if (selected.action === 'one-shot' || (selected.mode === 'off' && selected.action === 'none'))
103
117
  return decision;
118
+ if (selected.action === 'none' && selected.hasRules && !getReinforce(cwd))
119
+ return decision;
104
120
  let text;
105
121
  if (selected.action === 'status') {
106
122
  text = `Report this status without changing it: Caveman mode: ${selected.mode}`;
package/lib/mode.js CHANGED
@@ -2,6 +2,7 @@ import { createRequire } from 'node:module';
2
2
  const require = createRequire(import.meta.url);
3
3
  const parser = require('../vendor/caveman/src/hooks/caveman-parse.js');
4
4
  const modeConfig = require('../vendor/caveman/src/hooks/caveman-config.js');
5
+ export const getReinforce = modeConfig.getReinforce;
5
6
  /** A profile override wins; otherwise follow environment and file resolution. */
6
7
  export function defaultModeFor(configured, cwd) {
7
8
  if (configured !== undefined)
@@ -65,7 +66,9 @@ export class SessionModeTracker {
65
66
  const initial = reusable ? previous.mode : configured === 'manual' ? 'off' : configured;
66
67
  const events = session.snapshotEvents(reusable ? previous.seq : undefined, end);
67
68
  const mode = replay(initial, configured, events);
68
- this.states.set(session, { seq: end, configured, mode });
69
- return resolvePending(mode, configured, pending);
69
+ const hasRules = (reusable && previous.hasRules) || events.some(event => event.type === 'user/message' && event.data.source.kind === 'dsh-caveman-mode' &&
70
+ event.data.content.some(block => block.type === 'text' && /^Caveman mode: (?:caveman|ultracave|megacave)\n\n/u.test(block.text)));
71
+ this.states.set(session, { seq: end, configured, mode, hasRules });
72
+ return { ...resolvePending(mode, configured, pending), hasRules };
70
73
  }
71
74
  }
@@ -24,6 +24,10 @@ export interface Config {
24
24
  browseBinary?: string;
25
25
  mcpBinary?: string;
26
26
  memoryBinary?: string;
27
+ codeMode?: false | {
28
+ config: string;
29
+ workspace: string;
30
+ };
27
31
  }
28
32
  export declare const Config: z<Config>;
29
33
  /** Register skills and reinforce the selected mode per session. */
@@ -15,6 +15,7 @@ interface InputEvent {
15
15
  readonly type: string;
16
16
  readonly data: unknown;
17
17
  }
18
+ export declare const getReinforce: (startDir?: string) => boolean;
18
19
  /** A profile override wins; otherwise follow environment and file resolution. */
19
20
  export declare function defaultModeFor(configured: DefaultMode | undefined, cwd?: string): DefaultMode;
20
21
  /** Replay only user-authored messages, then evaluate the incoming batch. */
@@ -28,6 +29,7 @@ export declare class SessionModeTracker {
28
29
  resolve(configured: DefaultMode, session: Session, pending: readonly InputMessage[]): {
29
30
  mode: VoiceMode;
30
31
  action: ModeAction;
32
+ hasRules: boolean;
31
33
  };
32
34
  }
33
35
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lornatang/dsh-caveman",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Caveman integration for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -75,7 +75,7 @@
75
75
  }
76
76
  },
77
77
  "dependencies": {
78
- "@caveman-ai/cli": "4.1.0",
78
+ "@caveman-ai/cli": "4.2.0",
79
79
  "@caveman-ai/sdk": "1.2.0",
80
80
  "@deepseek-ai/schemastery": "~3.19.0",
81
81
  "undici": "^8.12.4",
@@ -92,29 +92,29 @@
92
92
  "devDependencies": {
93
93
  "@deepseek-ai/cordis": "~4.1.0",
94
94
  "@deepseek-ai/cordis-plugin-group": "1.1.0",
95
- "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
96
- "@deepseek-ai/dsh-agent-loop": "^0.2.2-rc.3",
97
- "@deepseek-ai/dsh-agent-preset": "0.2.2-rc.3",
98
- "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.3",
99
- "@deepseek-ai/dsh-fs-local": "0.2.2-rc.3",
100
- "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
101
- "@deepseek-ai/dsh-llm-pi-ai": "0.2.2-rc.3",
102
- "@deepseek-ai/dsh-mcp-manager": "0.2.2-rc.3",
103
- "@deepseek-ai/dsh-ptc-runtime": "0.2.2-rc.3",
104
- "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.3",
105
- "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.3",
106
- "@deepseek-ai/dsh-skill": "0.2.2-rc.3",
107
- "@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
108
- "@deepseek-ai/dsh-subagent-spawn-in-process": "0.2.2-rc.3",
109
- "@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.3",
110
- "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
111
- "@deepseek-ai/dsh-tool-executor-native": "^0.2.2-rc.3",
112
- "@deepseek-ai/dsh-tool-executor-ptc": "0.2.2-rc.3",
113
- "@deepseek-ai/dsh-tool-fs": "0.2.2-rc.3",
114
- "@deepseek-ai/dsh-tool-fs-search": "0.2.2-rc.3",
115
- "@deepseek-ai/dsh-tool-subagent": "0.2.2-rc.3",
116
- "@deepseek-ai/dsh-tools": "^0.2.2-rc.3",
117
- "@deepseek-ai/dsh-working-directory": "0.2.2-rc.3",
95
+ "@deepseek-ai/dsh-agent": "*",
96
+ "@deepseek-ai/dsh-agent-loop": "*",
97
+ "@deepseek-ai/dsh-agent-preset": "*",
98
+ "@deepseek-ai/dsh-agent-preset-registry": "*",
99
+ "@deepseek-ai/dsh-fs-local": "*",
100
+ "@deepseek-ai/dsh-llm": "*",
101
+ "@deepseek-ai/dsh-llm-pi-ai": "*",
102
+ "@deepseek-ai/dsh-mcp-manager": "*",
103
+ "@deepseek-ai/dsh-ptc-runtime": "*",
104
+ "@deepseek-ai/dsh-sandbox-policy": "*",
105
+ "@deepseek-ai/dsh-session-persistence-jsonl": "*",
106
+ "@deepseek-ai/dsh-skill": "*",
107
+ "@deepseek-ai/dsh-subagent": "*",
108
+ "@deepseek-ai/dsh-subagent-spawn-in-process": "*",
109
+ "@deepseek-ai/dsh-subprocess-local": "*",
110
+ "@deepseek-ai/dsh-system-prompt": "*",
111
+ "@deepseek-ai/dsh-tool-executor-native": "*",
112
+ "@deepseek-ai/dsh-tool-executor-ptc": "*",
113
+ "@deepseek-ai/dsh-tool-fs": "*",
114
+ "@deepseek-ai/dsh-tool-fs-search": "*",
115
+ "@deepseek-ai/dsh-tool-subagent": "*",
116
+ "@deepseek-ai/dsh-tools": "*",
117
+ "@deepseek-ai/dsh-working-directory": "*",
118
118
  "@types/node": "^26.6.6",
119
119
  "typescript": "^7.0.2"
120
120
  },
@@ -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
+ })