@lukstei/dsh-scratch-dir 0.0.0-stage → 0.2.2-rc.5.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lukas Steinbrecher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # @lukstei/dsh-scratch-dir
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ## Summary
4
+
5
+ Creates a per-session scratch directory at `.agents/scratch/<sessionId>` in the session working directory and tells the agent its path through a system prompt section. Agents use it for plans, notes and throwaway files instead of the repo root.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Use this package](#use-this-package)
10
+ - [Understand the implementation](#understand-the-implementation)
11
+ - [Further Exploration](#further-exploration)
12
+ - [Model Experience](#model-experience)
13
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
14
+ - [Dev Note](#dev-note)
15
+
16
+ -----
17
+
18
+ <a id="use-this-package"></a>
19
+ ## Use this package
20
+
21
+ Mount through the bundle patch ([`cordis.patch.yml`](cordis.patch.yml)):
22
+
23
+ ```yaml
24
+ - insert:
25
+ - id: scratch-dir
26
+ name: '@lukstei/dsh-scratch-dir'
27
+ config: {}
28
+ ```
29
+
30
+ No config fields. Required services: `systemPrompt`, `workingDirectory`.
31
+
32
+ Behavior, on each `agent/created`:
33
+
34
+ - Creates `<workingDirectory>/.agents/scratch/<sessionId>` (recursive).
35
+ - Creates `.agents/scratch/.gitignore` containing `*` if it does not exist (`wx` flag; an existing file is left alone). Scratch files stay out of git.
36
+ - Adds the system prompt section described under [Model Experience](#model-experience).
37
+ - Rejects a session id that would resolve outside `.agents/scratch` (parent directory must equal the scratch root). No directory and no prompt section; a warning is logged.
38
+ - Any filesystem error is logged as a warning and the agent starts without the section.
39
+
40
+ Exported helper `scratchDirectory(cwd, sessionId)` returns the directory or `undefined` for an unsafe id. [`@lukstei/dsh-session-handoff`](../dsh-session-handoff/README.md) imports it.
41
+
42
+ ### Plugin dependencies
43
+
44
+ Server-side only. `inject`: `systemPrompt`, `workingDirectory`.
45
+
46
+ | Plugin / service | Required? | Provided by | Effect without it |
47
+ |---|---|---|---|
48
+ | `systemPrompt` | Required | @deepseek-ai/dsh-system-prompt | Plugin stays pending; never applies. No prompt section. |
49
+ | `workingDirectory` | Required | @deepseek-ai/dsh-working-directory | Plugin stays pending; never applies. No directory created. |
50
+
51
+ Exports `scratchDirectory()` (pure function).
52
+
53
+ Used by: [`dsh-session-handoff`](../dsh-session-handoff/README.md) imports `scratchDirectory`; that is a code import, so mounting `scratch-dir` is not required.
54
+
55
+ -----
56
+
57
+ <a id="understand-the-implementation"></a>
58
+ ## Understand the implementation
59
+
60
+ <details>
61
+ <summary>Implementation internals — click to expand</summary>
62
+
63
+ Single file: [`src/index.ts`](src/index.ts). Tests: [`src/index.test.ts`](src/index.test.ts).
64
+
65
+ - The working directory is read with `ctx.workingDirectory.get(agent.session)` at agent creation. Later directory changes do not move the scratch directory.
66
+ - The section is registered on `agent.ctx.systemPrompt` with `interpolate: false`.
67
+ - Trust boundary: the session id is used as a path segment, so `scratchDirectory` checks `path.dirname(resolved) === scratchRoot`.
68
+
69
+ </details>
70
+
71
+ -----
72
+
73
+ <a id="further-exploration"></a>
74
+ ## Further Exploration
75
+
76
+ - Upstream: [DSH module graph](https://github.com/deepseek-ai/deepseek-harness/blob/master/docs/module-graph.md).
77
+
78
+ <a id="model-experience"></a>
79
+ ## Model Experience
80
+
81
+ ### Scratch directory section
82
+
83
+ #### What the model sees
84
+
85
+ One system prompt section, name `lukstei-dsh-plugins:scratch-directory`, order `10300`:
86
+
87
+ ```text
88
+ The scratch directory is located at <cwd>/.agents/scratch/<sessionId>.
89
+ ```
90
+
91
+ #### Token effect
92
+
93
+ One sentence plus an absolute path, roughly 20 tokens per agent.
94
+
95
+ #### KV Cache effect
96
+
97
+ The text is fixed for the agent's lifetime, so it does not invalidate the cache within a session. It contains the session id, so the prompt differs from other sessions from this section onward; content ordered after it cannot share a prefix across sessions.
98
+
99
+ <a id="known-limitations-and-deferred-work"></a>
100
+ ## Known Limitations and Deferred Work
101
+
102
+ - Directories are never cleaned up.
103
+ - The `.gitignore` is created only once; an existing one is not checked for content.
104
+ - Nothing stops the agent from writing elsewhere; the section is advisory.
105
+
106
+ <a id="dev-note"></a>
107
+ ### Dev Note
108
+
109
+ <details>
110
+ <summary>Working context for maintainers — click to expand</summary>
111
+
112
+ None.
113
+
114
+ </details>
@@ -0,0 +1,4 @@
1
+ - insert:
2
+ - id: scratch-dir
3
+ name: '@lukstei/dsh-scratch-dir'
4
+ config: {}
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@lukstei/dsh-scratch-dir",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.2-rc.5.4",
4
+ "description": "Scratch directory provisioner for DSH sessions",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "dsh": {
11
+ "bundle": {
12
+ "patch": "./cordis.patch.yml"
13
+ }
14
+ },
15
+ "peerDependencies": {
16
+ "@deepseek-ai/cordis": "*",
17
+ "@deepseek-ai/dsh-agent": "*",
18
+ "@deepseek-ai/dsh-system-prompt": "*",
19
+ "@deepseek-ai/dsh-working-directory": "*"
20
+ },
21
+ "devDependencies": {
22
+ "@deepseek-ai/cordis": "4.1.0",
23
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.5",
24
+ "@deepseek-ai/dsh-scope": "0.2.2-rc.5",
25
+ "@deepseek-ai/dsh-session": "0.2.2-rc.5",
26
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.5",
27
+ "@deepseek-ai/dsh-working-directory": "0.2.2-rc.5",
28
+ "@types/node": "^26.0.0",
29
+ "typescript": "^7.0.2"
30
+ },
31
+ "files": [
32
+ "src",
33
+ "README.md",
34
+ "cordis.patch.yml",
35
+ "!src/**/*.spec.*",
36
+ "!src/**/*.test.*",
37
+ "!src/**/*.stories.*",
38
+ "!src/**/stories",
39
+ "!src/**/*.e2e.*",
40
+ "!src/**/__snapshots__",
41
+ "!src/**/fixtures"
42
+ ],
43
+ "types": "./src/index.ts",
44
+ "license": "MIT",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/lukstei/dsh-plugins.git",
48
+ "directory": "packages/dsh-scratch-dir"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "scripts": {
54
+ "check": "biome check --reporter=concise .",
55
+ "typecheck": "tsc --noEmit",
56
+ "test": "node --experimental-test-module-mocks --test --test-reporter=dot",
57
+ "verify": "pnpm --silent run check && pnpm --silent run typecheck && pnpm --silent run test"
58
+ }
6
59
  }
package/src/index.ts ADDED
@@ -0,0 +1,74 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import type { Context } from "@deepseek-ai/cordis";
4
+ import type {} from "@deepseek-ai/dsh-agent";
5
+ import type {} from "@deepseek-ai/dsh-system-prompt";
6
+ import type {} from "@deepseek-ai/dsh-working-directory";
7
+
8
+ export const name = "scratch-dir";
9
+ export const inject = ["systemPrompt", "workingDirectory"];
10
+
11
+ const SECTION_NAME = "lukstei-dsh-plugins:scratch-directory";
12
+ const SECTION_ORDER = 10300;
13
+ const GITIGNORE = "*\n";
14
+
15
+ export function scratchDirectory(
16
+ cwd: string,
17
+ sessionId: string,
18
+ ): string | undefined {
19
+ const root = path.resolve(cwd, ".agents", "scratch");
20
+ const dir = path.resolve(root, sessionId);
21
+ if (path.dirname(dir) !== root) return undefined;
22
+ return dir;
23
+ }
24
+
25
+ async function ensureScratchDirectory(
26
+ cwd: string,
27
+ sessionId: string,
28
+ ): Promise<string | undefined> {
29
+ const dir = scratchDirectory(cwd, sessionId);
30
+ if (dir === undefined) return undefined;
31
+ const root = path.dirname(dir);
32
+ await mkdir(dir, { recursive: true });
33
+ try {
34
+ await writeFile(path.join(root, ".gitignore"), GITIGNORE, { flag: "wx" });
35
+ } catch (error) {
36
+ if (
37
+ !(error instanceof Error) ||
38
+ !("code" in error) ||
39
+ error.code !== "EEXIST"
40
+ )
41
+ throw error;
42
+ }
43
+ return dir;
44
+ }
45
+
46
+ export function apply(ctx: Context): void {
47
+ const logger = ctx.logger("scratch-dir");
48
+ ctx.on("agent/created", async ({ agent }): Promise<undefined> => {
49
+ let dir: string | undefined;
50
+ try {
51
+ dir = await ensureScratchDirectory(
52
+ ctx.workingDirectory.get(agent.session),
53
+ String(agent.session.id),
54
+ );
55
+ } catch (error) {
56
+ logger.warn(
57
+ `scratch-dir: could not prepare directory for ${agent.id}: ${String(error)}`,
58
+ );
59
+ return undefined;
60
+ }
61
+ if (dir === undefined) {
62
+ logger.warn(
63
+ `scratch-dir: unsafe session id "${agent.id}"; no scratch directory created`,
64
+ );
65
+ return undefined;
66
+ }
67
+ agent.ctx.systemPrompt.section({
68
+ name: SECTION_NAME,
69
+ order: SECTION_ORDER,
70
+ text: `The scratch directory is located at ${dir}.`,
71
+ interpolate: false,
72
+ });
73
+ });
74
+ }