@lornatang/dsh-caveman 0.1.3 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.5 - 2026-11-19
4
+
5
+ - Cache the verified local runtime identity for one second per endpoint, so a tool call performs one health check instead of two while a runtime restart still invalidates sessions.
6
+ - Skip the second read-and-hash of a read tool input when the runtime response carries no ccr:// recovery context.
7
+ - Cache per-session surface manifests by content generation and node count, so unchanged surfaces are not re-hashed on every agent step.
8
+ - Keep the verified analyzer binaries attached to this release under the new version.
9
+
10
+ ## 0.1.4 - 2026-11-19
11
+
12
+ - Restore the POSIX native-socket retry: a socket the runtime has not created yet is retried instead of disabling the call, while a replaced or foreign-owned path is still refused before any request is sent.
13
+ - Keep the verified analyzer binaries attached to this release under the new version.
14
+
3
15
  ## 0.1.3 - 2026-11-19
4
16
 
5
17
  - Simplify the system-prompt and request-header hooks by dropping unused handler parameters; behavior is unchanged.
package/README.md CHANGED
@@ -43,7 +43,7 @@ git clone https://github.com/Lornatang/dsh-caveman.git
43
43
  cd dsh-caveman
44
44
  npm ci
45
45
  npm pack
46
- dsh plugin --profile <name> add ./lornatang-dsh-caveman-0.1.3.tgz
46
+ dsh plugin --profile <name> add ./lornatang-dsh-caveman-0.1.5.tgz
47
47
  ```
48
48
 
49
49
  The `add` command composes the bundle into the profile. Its patches insert the `caveman` row, three Cavecrew presets, and their delegation tools. Restart DSH after `add` or `remove` so the profile reloads its composition.
package/README.zh.md CHANGED
@@ -43,7 +43,7 @@ git clone https://github.com/Lornatang/dsh-caveman.git
43
43
  cd dsh-caveman
44
44
  npm ci
45
45
  npm pack
46
- dsh plugin --profile <name> add ./lornatang-dsh-caveman-0.1.3.tgz
46
+ dsh plugin --profile <name> add ./lornatang-dsh-caveman-0.1.5.tgz
47
47
  ```
48
48
 
49
49
  `add` 命令把 bundle 组合进 profile。patch 会插入 `caveman` 行、三个 Cavecrew 预设及其委派工具。`add` 或 `remove` 后重启 DSH,使 profile 重新加载配置。
@@ -151,14 +151,23 @@ export function resolveOriginalResult(session, event) {
151
151
  cache.set(item, current);
152
152
  return current;
153
153
  }
154
+ const manifests = new WeakMap();
154
155
  function manifestFor(session) {
155
- return session.surface.nodes.map(seq => {
156
+ const generation = session.surface.contentGeneration;
157
+ const count = session.surface.nodes.length;
158
+ const cached = manifests.get(session);
159
+ if (cached && cached.generation === generation && cached.count === count)
160
+ return cached.value;
161
+ const entries = session.surface.nodes.map(seq => {
156
162
  let event = session.eventAt(seq);
157
163
  if (event.type === 'tool/result')
158
164
  event = resolveOriginalResult(session, event);
159
165
  const data = event.type === 'user/message' ? event.data : 'message' in event.data ? event.data.message : event.data;
160
166
  return { id: `seq-${event.seq}`, sha256: createHash('sha256').update(JSON.stringify(data)).digest('hex') };
161
167
  });
168
+ const value = { entries, bytes: Buffer.byteLength(JSON.stringify(entries), 'utf8') };
169
+ manifests.set(session, { generation, count, value });
170
+ return value;
162
171
  }
163
172
  function surfaceMatchesManifest(session, manifest) {
164
173
  if (session.surface.nodes.length !== manifest.length)
@@ -372,7 +381,7 @@ export function registerCompression(ctx, endpoint, automatic) {
372
381
  }
373
382
  const manifest = manifestFor(session);
374
383
  const maxSegments = capabilities.limits.max_segments ?? 256;
375
- const byteBudget = Math.max(0, capabilities.limits.request_bytes - Buffer.byteLength(JSON.stringify(manifest), 'utf8') - 16_384);
384
+ const byteBudget = Math.max(0, capabilities.limits.request_bytes - manifest.bytes - 16_384);
376
385
  const prepared = eligible.map(candidate => {
377
386
  const sourceId = `seq-${resolveOriginalResult(session, candidate.event).seq}`;
378
387
  const segments = candidate.blocks.map(block => ({
@@ -385,7 +394,7 @@ export function registerCompression(ctx, endpoint, automatic) {
385
394
  try {
386
395
  for (const group of batches) {
387
396
  signal.throwIfAborted();
388
- if (!surfaceMatchesManifest(session, manifest)) {
397
+ if (!surfaceMatchesManifest(session, manifest.entries)) {
389
398
  restore(session);
390
399
  return decision;
391
400
  }
@@ -394,13 +403,13 @@ export function registerCompression(ctx, endpoint, automatic) {
394
403
  continue;
395
404
  const segments = candidates.flatMap(candidate => candidate.segments);
396
405
  const optimization = await runtime.optimize({
397
- scope, binding, adapter: ADAPTER, manifest,
406
+ scope, binding, adapter: ADAPTER, manifest: manifest.entries,
398
407
  candidates: segments,
399
408
  model: { provider: modelSelection.provider, id: modelSelection.model, protocol: 'dsh' },
400
409
  recoveryOverheadText: JSON.stringify(published), signal,
401
410
  });
402
411
  signal.throwIfAborted();
403
- if (!surfaceMatchesManifest(session, manifest) || ctx.tools.get(tool.name, agent, toolSet) !== tool) {
412
+ if (!surfaceMatchesManifest(session, manifest.entries) || ctx.tools.get(tool.name, agent, toolSet) !== tool) {
404
413
  restore(session);
405
414
  return decision;
406
415
  }
package/lib/native.js CHANGED
@@ -77,23 +77,28 @@ function validResponse(value) {
77
77
  return true;
78
78
  }
79
79
  /** Refuse a replaced socket path before sending prompt terms or tool data over it. */
80
- async function trustedSocket(path) {
80
+ async function socketTrust(path) {
81
81
  if (process.platform === 'win32')
82
- return true;
82
+ return 'trusted';
83
83
  try {
84
84
  const info = await lstat(path);
85
85
  if (!info.isSocket())
86
- return false;
87
- return typeof process.getuid === 'function' ? info.uid === process.getuid() : true;
86
+ return 'untrusted';
87
+ return typeof process.getuid === 'function' && info.uid !== process.getuid() ? 'untrusted' : 'trusted';
88
88
  }
89
- catch {
90
- return false;
89
+ catch (error) {
90
+ // A runtime that is still starting has no socket yet. Report it as absent so the
91
+ // caller may retry its connection, and check this path again before each retry.
92
+ if (error.code === 'ENOENT')
93
+ return 'missing';
94
+ return 'untrusted';
91
95
  }
92
96
  }
93
97
  export async function nativeCall(home, request, signal) {
94
98
  if (signal?.aborted)
95
99
  return undefined;
96
- if (!await trustedSocket(nativeSocketPath(home)))
100
+ const socketPath = nativeSocketPath(home);
101
+ if (await socketTrust(socketPath) === 'untrusted')
97
102
  return undefined;
98
103
  const payload = Buffer.from(JSON.stringify(request) + '\n');
99
104
  if (payload.length > 2 * 1024 * 1024)
@@ -103,7 +108,7 @@ export async function nativeCall(home, request, signal) {
103
108
  let connected = false;
104
109
  let size = 0;
105
110
  const chunks = [];
106
- const socket = connect({ path: nativeSocketPath(home) });
111
+ const socket = connect({ path: socketPath });
107
112
  const finish = (response, retry = false) => {
108
113
  if (finished)
109
114
  return;
@@ -156,6 +161,8 @@ export async function nativeCall(home, request, signal) {
156
161
  catch {
157
162
  return undefined;
158
163
  }
164
+ if (await socketTrust(socketPath) === 'untrusted')
165
+ return undefined;
159
166
  return (await attempt()).response;
160
167
  }
161
168
  async function inputState(ctx, cwd, input, signal) {
@@ -197,15 +204,32 @@ async function inputState(ctx, cwd, input, signal) {
197
204
  return undefined;
198
205
  }
199
206
  }
207
+ const RUNTIME_VERIFICATION_TTL_MS = 1_000;
208
+ const verifiedInstances = new Map();
200
209
  async function runtimeInstance(endpoint, home, signal) {
201
- if (!await verifiedRuntime(endpoint, process.env, signal))
210
+ signal?.throwIfAborted();
211
+ const key = `${endpoint}\u0000${home}`;
212
+ const cached = verifiedInstances.get(key);
213
+ if (cached && cached.expires > Date.now())
214
+ return cached.token;
215
+ if (!await verifiedRuntime(endpoint, process.env, signal)) {
216
+ verifiedInstances.delete(key);
202
217
  return undefined;
218
+ }
203
219
  try {
204
220
  const port = Number(new URL(endpoint).port || 80);
205
221
  const token = JSON.parse(readFileSync(join(home, 'run', `${port}.json`), 'utf8')).instance_token;
206
- return typeof token === 'string' && token ? token : undefined;
222
+ if (typeof token !== 'string' || !token) {
223
+ verifiedInstances.delete(key);
224
+ return undefined;
225
+ }
226
+ if (verifiedInstances.size >= 32)
227
+ verifiedInstances.delete(verifiedInstances.keys().next().value);
228
+ verifiedInstances.set(key, { token, expires: Date.now() + RUNTIME_VERIFICATION_TTL_MS });
229
+ return token;
207
230
  }
208
231
  catch {
232
+ verifiedInstances.delete(key);
209
233
  return undefined;
210
234
  }
211
235
  }
@@ -339,16 +363,19 @@ export function registerNative(ctx, endpoint, policy) {
339
363
  const before = await nativeCall(home, { ...base, event: { type: 'tool.before', timestamp_ms: Date.now() },
340
364
  tool: { name: exec.name, input: exec.arguments, ...(beforeState ? { input_state: beforeState } : {}) } }, exec.signal);
341
365
  const result = await next();
366
+ const recoveryContext = before?.context?.includes('ccr://') ?? false;
342
367
  let afterState;
343
368
  if (!exec.signal.aborted && await runtimeInstance(endpoint, home, exec.signal) === state.instance) {
344
- afterState = exec.name === 'read' ? await inputState(ctx, state.session.cwd, exec.arguments, exec.signal) : undefined;
369
+ // The comparison only gates a ccr:// reminder, so skip the second full
370
+ // read-and-hash when the before response carries no recovery context.
371
+ afterState = exec.name === 'read' && recoveryContext ? await inputState(ctx, state.session.cwd, exec.arguments, exec.signal) : undefined;
345
372
  const textOnly = result.content.every(block => block.type === 'text') && result.content.reduce((sum, block) => sum + (block.type === 'text' ? Buffer.byteLength(block.text, 'utf8') : 0), 0) <= 1_500_000;
346
373
  const content = textOnly ? result.content.map(block => block.type === 'text' ? block.text : '').join('\n') : '';
347
374
  await nativeCall(home, { ...base, event: { type: result.isError ? 'tool.failure' : 'tool.after', timestamp_ms: Date.now() },
348
375
  tool: { name: exec.name, input: exec.arguments, ...(afterState ? { input_state: afterState } : {}), ...(content ? { output: Buffer.from(content).toString('base64') } : {}) } }, exec.signal);
349
376
  }
350
377
  const canRecover = exec.toolSet && ctx.tools.get('mcp__caveman__caveman_retrieve', exec.agent, exec.toolSet);
351
- if (!policy.core || state.specialized || !before?.context || (before.context.includes('ccr://') && (!canRecover || !beforeState || beforeState !== afterState)) || exec.signal.aborted)
378
+ if (!policy.core || state.specialized || !before?.context || (recoveryContext && (!canRecover || !beforeState || beforeState !== afterState)) || exec.signal.aborted)
352
379
  return result;
353
380
  const reminder = createUserMessage({ source: { kind: 'dsh-caveman-native', form: 'notice' }, content: [{ type: 'text', text: before.context }] });
354
381
  return { ...result, additionalContexts: [...result.additionalContexts ?? [], reminder] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lornatang/dsh-caveman",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Caveman integration for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.3",
2
+ "version": "0.1.5",
3
3
  "binaries": {
4
4
  "linux-x64": {
5
5
  "name": "dsh-caveman-learn_linux_amd64",