dsh-compaction-weave 0.0.0-stage → 0.3.3
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 +97 -0
- package/LICENSE +21 -0
- package/README.en.md +136 -0
- package/README.md +139 -2
- package/cordis.patch.yml +19 -0
- package/docs/architecture.md +84 -0
- package/docs/benchmarks/published-0.3.2-rc.1-tests.json +576 -0
- package/docs/benchmarks/rc2-documentation.json +41 -0
- package/docs/benchmarks/rc2-linux-tests.json +590 -0
- package/docs/benchmarks/rc2-live-and-cost.json +746 -0
- package/docs/benchmarks/rc3-host-compatibility.json +2314 -0
- package/docs/benchmarks/rc4-tests.json +617 -0
- package/docs/benchmarks/review35-compression.json +117 -0
- package/docs/benchmarks/v0.3.2-live-four-way.json +3495 -0
- package/docs/benchmarks/v0.3.2-tests.json +590 -0
- package/docs/configuration.md +131 -0
- package/docs/development.md +88 -0
- package/docs/en/architecture.md +75 -0
- package/docs/en/configuration.md +131 -0
- package/docs/en/development.md +86 -0
- package/docs/en/feedback.md +47 -0
- package/docs/en/principles.md +235 -0
- package/docs/en/testing.md +368 -0
- package/docs/en/troubleshooting.md +59 -0
- package/docs/feedback.md +47 -0
- package/docs/images/principles-context.en.svg +77 -0
- package/docs/images/principles-context.zh.svg +77 -0
- package/docs/images/principles-pipeline.en.svg +93 -0
- package/docs/images/principles-pipeline.zh.svg +93 -0
- package/docs/images/principles-recovery.en.svg +46 -0
- package/docs/images/principles-recovery.zh.svg +46 -0
- package/docs/principles.md +235 -0
- package/docs/test-results.json +634 -0
- package/docs/testing.md +358 -0
- package/docs/troubleshooting.md +59 -0
- package/lib/abort.js +13 -0
- package/lib/action-state.js +60 -0
- package/lib/atomic-replace.js +18 -0
- package/lib/attachments.js +76 -0
- package/lib/audit-reject.js +161 -0
- package/lib/audit.js +939 -0
- package/lib/cache-policy.js +71 -0
- package/lib/client.js +696 -0
- package/lib/command-compact.js +38 -0
- package/lib/command-heartbeat.js +61 -0
- package/lib/config.js +596 -0
- package/lib/constraint-scope.js +37 -0
- package/lib/continuation-budget.js +69 -0
- package/lib/continuation-pending.js +57 -0
- package/lib/continuation-progress.js +46 -0
- package/lib/continuation.js +287 -0
- package/lib/engine-entry.js +103 -0
- package/lib/engine.js +2485 -0
- package/lib/failure-diagnostics.js +220 -0
- package/lib/history-source.js +74 -0
- package/lib/history.js +712 -0
- package/lib/idle-compaction.js +64 -0
- package/lib/index.js +611 -0
- package/lib/instruction-source.js +163 -0
- package/lib/journal.js +164 -0
- package/lib/manual-error.js +179 -0
- package/lib/memory-policy.js +383 -0
- package/lib/meter.js +387 -0
- package/lib/observation-mask.js +390 -0
- package/lib/proactive.js +108 -0
- package/lib/progress-facts.js +347 -0
- package/lib/progress-state.js +30 -0
- package/lib/prompt.js +194 -0
- package/lib/reconstruct.js +72 -0
- package/lib/reference-input.js +107 -0
- package/lib/region.js +972 -0
- package/lib/source-provenance.js +58 -0
- package/lib/source-recovery.js +22 -0
- package/lib/source-refs.js +137 -0
- package/lib/state.js +46 -0
- package/lib/storage-path.js +42 -0
- package/lib/summary-budget.js +187 -0
- package/lib/summary-config.js +308 -0
- package/lib/summary-progress.js +56 -0
- package/lib/summary-retry.js +27 -0
- package/lib/summary-timeout.js +68 -0
- package/lib/summary.js +476 -0
- package/lib/tools.js +341 -0
- package/lib/transaction-host.js +252 -0
- package/lib/transaction.js +285 -0
- package/lib/validate.js +503 -0
- package/lib/version.js +3 -0
- package/lib/window.js +120 -0
- package/lib/work-report.js +55 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +71 -4
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {diagnosticText} from './failure-diagnostics.js';
|
|
2
|
+
// Keep host validation, cancellation and success. Decorate failures using only
|
|
3
|
+
// this invocation's diagnostic receipt, with durable timeout/budget fallback.
|
|
4
|
+
import { summaryTimeoutText, timeoutForCommand } from './summary-timeout.js';
|
|
5
|
+
import { withCommandHeartbeat } from './command-heartbeat.js';
|
|
6
|
+
import {continuationBudgetText,budgetForCommand} from './continuation-budget.js';
|
|
7
|
+
export const name = 'compaction-weave-command-compact';
|
|
8
|
+
export const inject = ['commands','compaction','loader'];
|
|
9
|
+
|
|
10
|
+
export function decorateCompactCommand(definition, compaction) {
|
|
11
|
+
if (definition?.name !== 'compact' || typeof definition.handler !== 'function') return definition;
|
|
12
|
+
return {...definition, async handler(invocation) {
|
|
13
|
+
let result;
|
|
14
|
+
try { result = await withCommandHeartbeat(invocation, () => definition.handler(invocation)); }
|
|
15
|
+
catch(error) {
|
|
16
|
+
const diagnostic=compaction?.failureForCommand?.(invocation.agent?.session,invocation.commandId);
|
|
17
|
+
if(invocation.signal?.aborted || !diagnostic)throw error;
|
|
18
|
+
return {kind:'error',text:diagnostic.explanation+diagnosticText(diagnostic)};
|
|
19
|
+
}
|
|
20
|
+
if (result?.kind !== 'error' || invocation.signal?.aborted) return result;
|
|
21
|
+
const diagnostic=compaction?.failureForCommand?.(invocation.agent?.session,invocation.commandId);
|
|
22
|
+
if(diagnostic)return {...result,text:diagnostic.explanation+diagnosticText(diagnostic)};
|
|
23
|
+
const budget=budgetForCommand(invocation.agent?.session,invocation.commandId);
|
|
24
|
+
if(budget)return {...result,text:continuationBudgetText(budget)};
|
|
25
|
+
const timeout = timeoutForCommand(invocation.agent?.session, invocation.commandId);
|
|
26
|
+
return timeout ? {...result,text:summaryTimeoutText(timeout)} : result;
|
|
27
|
+
}};
|
|
28
|
+
}
|
|
29
|
+
export async function apply(ctx) {
|
|
30
|
+
const host = await ctx.loader.import('@deepseek-ai/dsh-command-compact', () => '');
|
|
31
|
+
if (typeof host?.apply !== 'function') throw new Error('Host compact command implementation is unavailable.');
|
|
32
|
+
return host.apply({
|
|
33
|
+
compaction:ctx.compaction,
|
|
34
|
+
commands:{register:definition=>ctx.commands.register(decorateCompactCommand(definition,ctx.compaction))},
|
|
35
|
+
effect:ctx.effect.bind(ctx),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export default {name,inject,apply};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
|
|
3
|
+
// Scope the response to its real admitted HTTP invocation without reading or
|
|
4
|
+
// replacing its body, signal, final status, headers or RPC result.
|
|
5
|
+
const requests = new AsyncLocalStorage();
|
|
6
|
+
export const COMMAND_HEARTBEAT_MS = 15000;
|
|
7
|
+
|
|
8
|
+
export function createCommandHeartbeatScope({intervalMs = COMMAND_HEARTBEAT_MS} = {}) {
|
|
9
|
+
const active = new Set();
|
|
10
|
+
let disposed = false;
|
|
11
|
+
return {
|
|
12
|
+
handle(request, response, next) {
|
|
13
|
+
if (disposed || request?.method !== 'POST' || request.url?.split('?')[0] !== '/api/commands/execute') return next();
|
|
14
|
+
return requests.run({response, intervalMs, active, available:()=>!disposed}, next);
|
|
15
|
+
},
|
|
16
|
+
dispose() {
|
|
17
|
+
disposed = true;
|
|
18
|
+
for (const stop of [...active]) stop();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function installCommandHeartbeat(ctx) {
|
|
24
|
+
// Minimal/non-web hosts may expose only the engine configuration seam.
|
|
25
|
+
if (typeof ctx?.on !== 'function' || typeof ctx?.effect !== 'function') return;
|
|
26
|
+
const scope = createCommandHeartbeatScope();
|
|
27
|
+
const remove = ctx.on('connection/request', (request,response,next)=>scope.handle(request,response,next), {global:true});
|
|
28
|
+
ctx.effect(()=>()=>{scope.dispose();if(typeof remove==='function')remove();});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Only plugin-owned compaction commands opt in, after native RPC admission. */
|
|
32
|
+
export async function withCommandHeartbeat(invocation, run) {
|
|
33
|
+
const current = requests.getStore();
|
|
34
|
+
if (!current?.available() || invocation?.signal?.aborted || invocation?.rawInput?.trim()) return run();
|
|
35
|
+
const {response,intervalMs,active} = current;
|
|
36
|
+
if (typeof response?.writeProcessing !== 'function' || response.headersSent || response.destroyed || response.writableEnded) return run();
|
|
37
|
+
let timer, stopped = false;
|
|
38
|
+
const stop = () => {
|
|
39
|
+
if (stopped) return;
|
|
40
|
+
stopped = true;
|
|
41
|
+
clearInterval(timer);
|
|
42
|
+
response.off('close',stop);
|
|
43
|
+
response.off('finish',stop);
|
|
44
|
+
invocation.signal?.removeEventListener('abort',stop);
|
|
45
|
+
active.delete(stop);
|
|
46
|
+
};
|
|
47
|
+
const pulse = () => {
|
|
48
|
+
if (response.destroyed || response.writableEnded || response.headersSent || invocation.signal?.aborted) {stop();return;}
|
|
49
|
+
// 102 is informational: it keeps the relay's header wait alive without
|
|
50
|
+
// committing a 200 response or inserting bytes into the JSON envelope.
|
|
51
|
+
try { response.writeProcessing(); } catch { stop(); }
|
|
52
|
+
};
|
|
53
|
+
active.add(stop);
|
|
54
|
+
response.once('close',stop);
|
|
55
|
+
response.once('finish',stop);
|
|
56
|
+
invocation.signal?.addEventListener('abort',stop,{once:true});
|
|
57
|
+
timer = setInterval(pulse,intervalMs);
|
|
58
|
+
timer.unref?.();
|
|
59
|
+
pulse();
|
|
60
|
+
try { return await run(); } finally { stop(); }
|
|
61
|
+
}
|