dsh-context-mode 0.1.3 → 0.2.0
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/LICENSING.md +37 -0
- package/README.md +39 -13
- package/lib/types/cjk.d.ts +54 -0
- package/lib/types/cjk.d.ts.map +1 -0
- package/lib/types/cjk.js +64 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +65 -21
- package/lib/types/output-containment.d.ts +35 -0
- package/lib/types/output-containment.d.ts.map +1 -0
- package/lib/types/output-containment.js +103 -0
- package/lib/types/routing.d.ts +3 -1
- package/lib/types/routing.d.ts.map +1 -1
- package/lib/types/routing.js +81 -6
- package/package.json +9 -5
- package/skills/context-mode/SKILL.md +104 -11
- package/vendor/context-mode/LICENSE +94 -0
- package/vendor/context-mode/server.bundle.mjs +1126 -0
- package/vendor/context-mode/src/cli.ts +2040 -0
- package/vendor/context-mode/src/db-base.ts +617 -0
- package/vendor/context-mode/src/executor.ts +785 -0
- package/vendor/context-mode/src/exit-classify.ts +33 -0
- package/vendor/context-mode/src/fetch-cache.ts +15 -0
- package/vendor/context-mode/src/lifecycle.ts +305 -0
- package/vendor/context-mode/src/platform/client-map.ts +45 -0
- package/vendor/context-mode/src/platform/detect.ts +645 -0
- package/vendor/context-mode/src/platform/dsh.ts +206 -0
- package/vendor/context-mode/src/platform/types.ts +503 -0
- package/vendor/context-mode/src/runPool.ts +81 -0
- package/vendor/context-mode/src/runtime.ts +765 -0
- package/vendor/context-mode/src/search/auto-memory.ts +200 -0
- package/vendor/context-mode/src/search/ctx-search-schema.ts +143 -0
- package/vendor/context-mode/src/search/flood-guard.ts +111 -0
- package/vendor/context-mode/src/search/unified.ts +176 -0
- package/vendor/context-mode/src/security.ts +889 -0
- package/vendor/context-mode/src/server.ts +4991 -0
- package/vendor/context-mode/src/session/analytics.ts +3085 -0
- package/vendor/context-mode/src/session/db.ts +1726 -0
- package/vendor/context-mode/src/session/error-classifier.ts +392 -0
- package/vendor/context-mode/src/session/event-emit.ts +132 -0
- package/vendor/context-mode/src/session/extract.ts +2958 -0
- package/vendor/context-mode/src/session/index.ts +130 -0
- package/vendor/context-mode/src/session/model-prices.json +429 -0
- package/vendor/context-mode/src/session/persist-tool-calls.ts +128 -0
- package/vendor/context-mode/src/session/pricing.ts +191 -0
- package/vendor/context-mode/src/session/project-attribution.ts +309 -0
- package/vendor/context-mode/src/session/purge.ts +338 -0
- package/vendor/context-mode/src/session/retrieval-marker.ts +65 -0
- package/vendor/context-mode/src/session/snapshot.ts +577 -0
- package/vendor/context-mode/src/store-directory.ts +290 -0
- package/vendor/context-mode/src/store.ts +2071 -0
- package/vendor/context-mode/src/truncate.ts +154 -0
- package/vendor/context-mode/src/types.ts +147 -0
- package/vendor/context-mode/src/util/claude-config.ts +95 -0
- package/vendor/context-mode/src/util/hook-config.ts +78 -0
- package/vendor/context-mode/src/util/jsonc.ts +70 -0
- package/vendor/context-mode/src/util/plugin-cache-integrity.ts +167 -0
- package/vendor/context-mode/src/util/project-dir.ts +347 -0
- package/vendor/context-mode/src/util/sibling-mcp.ts +228 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* platform/dsh — the only platform adapter this fork ships.
|
|
3
|
+
*
|
|
4
|
+
* The upstream project carries eighteen hook adapters (Claude Code, Codex,
|
|
5
|
+
* Cursor, Gemini CLI, …) because each host wires hooks differently. This fork
|
|
6
|
+
* targets DSH alone, so those adapters were removed and this class takes their
|
|
7
|
+
* place.
|
|
8
|
+
*
|
|
9
|
+
* DSH does not use JSON-stdio hooks: it exposes a Cordis service surface
|
|
10
|
+
* (`tools.guard`, `tools/post-execute`, `systemPrompt.context`), so the hook
|
|
11
|
+
* capabilities below are all false by design. The DSH adapter layer in the
|
|
12
|
+
* parent package implements the equivalent behaviour natively, and this class
|
|
13
|
+
* exists so the remaining upstream code that calls `getAdapter()` keeps a
|
|
14
|
+
* working, honest answer.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { resolve } from "node:path";
|
|
18
|
+
import type {
|
|
19
|
+
DiagnosticResult,
|
|
20
|
+
HookAdapter,
|
|
21
|
+
HookParadigm,
|
|
22
|
+
HookRegistration,
|
|
23
|
+
PlatformCapabilities,
|
|
24
|
+
SessionStartEvent,
|
|
25
|
+
PreCompactEvent,
|
|
26
|
+
PreToolUseEvent,
|
|
27
|
+
PostToolUseEvent,
|
|
28
|
+
PreToolUseResponse,
|
|
29
|
+
PostToolUseResponse,
|
|
30
|
+
PreCompactResponse,
|
|
31
|
+
SessionStartResponse,
|
|
32
|
+
} from "./types.js";
|
|
33
|
+
import { getSessionDirSegments } from "./detect.js";
|
|
34
|
+
|
|
35
|
+
/** Capabilities for a host whose integration is a service surface, not hooks. */
|
|
36
|
+
const DSH_CAPABILITIES: PlatformCapabilities = {
|
|
37
|
+
preToolUse: false,
|
|
38
|
+
postToolUse: false,
|
|
39
|
+
preCompact: false,
|
|
40
|
+
sessionStart: false,
|
|
41
|
+
canModifyArgs: false,
|
|
42
|
+
canModifyOutput: false,
|
|
43
|
+
canInjectSessionContext: false,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export class DshAdapter implements HookAdapter {
|
|
47
|
+
readonly name = "DSH";
|
|
48
|
+
readonly paradigm: HookParadigm = "mcp-only";
|
|
49
|
+
readonly capabilities: PlatformCapabilities = DSH_CAPABILITIES;
|
|
50
|
+
|
|
51
|
+
private readonly platform: string;
|
|
52
|
+
|
|
53
|
+
constructor(platform = "pi") {
|
|
54
|
+
this.platform = platform;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ── Input parsing ──────────────────────────────────────
|
|
58
|
+
// DSH never routes a JSON-stdio hook through here. These methods satisfy the
|
|
59
|
+
// contract and fail loudly if a future caller assumes otherwise.
|
|
60
|
+
|
|
61
|
+
parsePreToolUseInput(_raw: unknown): PreToolUseEvent {
|
|
62
|
+
throw new Error("DSH routes tool guard decisions through Cordis, not JSON-stdio hooks");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
parsePostToolUseInput(_raw: unknown): PostToolUseEvent {
|
|
66
|
+
throw new Error("DSH routes tool results through Cordis, not JSON-stdio hooks");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
parsePreCompactInput(_raw: unknown): PreCompactEvent {
|
|
70
|
+
throw new Error("DSH routes compaction through session events, not JSON-stdio hooks");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
parseSessionStartInput(_raw: unknown): SessionStartEvent {
|
|
74
|
+
throw new Error("DSH injects session context through systemPrompt, not JSON-stdio hooks");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── Response formatting ────────────────────────────────
|
|
78
|
+
// No JSON-stdio path exists, so there is nothing to format.
|
|
79
|
+
|
|
80
|
+
formatPreToolUseResponse(_response: PreToolUseResponse): undefined {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
formatPostToolUseResponse(_response: PostToolUseResponse): undefined {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
formatPreCompactResponse(_response: PreCompactResponse): undefined {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
formatSessionStartResponse(_response: SessionStartResponse): undefined {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ── Configuration ──────────────────────────────────────
|
|
97
|
+
// DSH configuration lives in the DSH profile's cordis patch, not in a
|
|
98
|
+
// third-party settings file, so these report the DSH-owned storage root.
|
|
99
|
+
|
|
100
|
+
getSettingsPath(): string {
|
|
101
|
+
return resolve(process.env.CONTEXT_MODE_DIR ?? "", "settings.json");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getConfigDir(projectDir?: string): string {
|
|
105
|
+
return projectDir && projectDir.length > 0 ? resolve(projectDir) : process.cwd();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
getInstructionFiles(): string[] {
|
|
109
|
+
return ["AGENTS.md"];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getSessionDir(): string {
|
|
113
|
+
const segments = getSessionDirSegments(this.platform);
|
|
114
|
+
const root = process.env.CONTEXT_MODE_DIR;
|
|
115
|
+
if (root && root.length > 0) return resolve(root, "sessions");
|
|
116
|
+
return segments === null ? resolve(process.cwd(), "sessions") : resolve(...segments);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getMemoryDir(projectDir?: string): string {
|
|
120
|
+
const root = process.env.CONTEXT_MODE_DIR ?? process.cwd();
|
|
121
|
+
return resolve(root, "memory", projectDir ?? "");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
generateHookConfig(_pluginRoot: string): HookRegistration {
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
readSettings(): Record<string, unknown> | null {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
writeSettings(_settings: Record<string, unknown>): void {
|
|
133
|
+
// DSH configuration is declarative; the adapter never rewrites host files.
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
backupSettings(): string | null {
|
|
137
|
+
// Nothing to back up: DSH settings live in the profile's cordis patch,
|
|
138
|
+
// which this adapter never modifies.
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ── Diagnostics ────────────────────────────────────────
|
|
143
|
+
|
|
144
|
+
validateHooks(_pluginRoot: string): DiagnosticResult[] {
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
check: "Hook support",
|
|
148
|
+
status: "pass",
|
|
149
|
+
message:
|
|
150
|
+
"DSH integrates context-mode through native Cordis tools, guards, " +
|
|
151
|
+
"and prompt sections rather than external hook scripts.",
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
checkPluginRegistration(): DiagnosticResult {
|
|
157
|
+
return {
|
|
158
|
+
check: "DSH plugin registration",
|
|
159
|
+
status: "pass",
|
|
160
|
+
message: "context-mode is bridged by the dsh-context-mode plugin.",
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
getInstalledVersion(): string {
|
|
165
|
+
return "standalone";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
configureAllHooks(_pluginRoot: string): string[] {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
setHookPermissions(_pluginRoot: string): string[] {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
updatePluginRegistry(_pluginRoot: string, _version: string): void {
|
|
177
|
+
// No external registry: the plugin ships with the DSH profile.
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
getRoutingInstructions(): string {
|
|
181
|
+
return (
|
|
182
|
+
"# context-mode\n\n" +
|
|
183
|
+
"Use the context-mode tools (ctx_execute, ctx_execute_file, ctx_batch_execute, " +
|
|
184
|
+
"ctx_fetch_and_index, ctx_index, ctx_search) instead of inline shell or HTTP " +
|
|
185
|
+
"calls for data-heavy operations."
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Extract the installed plugin root from `codex plugin list` output.
|
|
192
|
+
*
|
|
193
|
+
* This helper was owned by the Codex adapter upstream. It survives here because
|
|
194
|
+
* `server.ts` probes for a Codex installation to locate hook scripts, and the
|
|
195
|
+
* parsing itself carries no Codex runtime dependency.
|
|
196
|
+
*
|
|
197
|
+
* @param raw - captured stdout of `codex plugin list`.
|
|
198
|
+
* @returns the plugin root path, or null when the line is absent.
|
|
199
|
+
*/
|
|
200
|
+
export function parseCodexContextModePluginRoot(raw: string): string | null {
|
|
201
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
202
|
+
const match = line.match(/^\s*context-mode@context-mode\s+installed,\s+enabled\s+\S+\s+(.+?)\s*$/);
|
|
203
|
+
if (match?.[1]) return match[1].trim();
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|