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

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.
Files changed (2) hide show
  1. package/dist/index.js +49 -0
  2. package/package.json +10 -4
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ // src/index.ts
4
+ const name = "scratch-dir";
5
+ const inject = ["systemPrompt", "workingDirectory"];
6
+ const SECTION_NAME = "lukstei-dsh-plugins:scratch-directory";
7
+ const SECTION_ORDER = 10300;
8
+ const GITIGNORE = "*\n";
9
+ function scratchDirectory(cwd, sessionId) {
10
+ const root = path.resolve(cwd, ".agents", "scratch");
11
+ const dir = path.resolve(root, sessionId);
12
+ if (path.dirname(dir) !== root) return void 0;
13
+ return dir;
14
+ }
15
+ async function ensureScratchDirectory(cwd, sessionId) {
16
+ const dir = scratchDirectory(cwd, sessionId);
17
+ if (dir === void 0) return void 0;
18
+ const root = path.dirname(dir);
19
+ await mkdir(dir, { recursive: true });
20
+ try {
21
+ await writeFile(path.join(root, ".gitignore"), GITIGNORE, { flag: "wx" });
22
+ } catch (error) {
23
+ if (!(error instanceof Error) || !("code" in error) || error.code !== "EEXIST") throw error;
24
+ }
25
+ return dir;
26
+ }
27
+ function apply(ctx) {
28
+ const logger = ctx.logger("scratch-dir");
29
+ ctx.on("agent/created", async ({ agent }) => {
30
+ let dir;
31
+ try {
32
+ dir = await ensureScratchDirectory(ctx.workingDirectory.get(agent.session), String(agent.session.id));
33
+ } catch (error) {
34
+ logger.warn(`scratch-dir: could not prepare directory for ${agent.id}: ${String(error)}`);
35
+ return;
36
+ }
37
+ if (dir === void 0) {
38
+ logger.warn(`scratch-dir: unsafe session id "${agent.id}"; no scratch directory created`);
39
+ return;
40
+ }
41
+ agent.ctx.systemPrompt.section({
42
+ name: SECTION_NAME,
43
+ order: SECTION_ORDER,
44
+ text: `The scratch directory is located at ${dir}.`,
45
+ interpolate: false
46
+ });
47
+ });
48
+ }
49
+ export { apply, inject, name, scratchDirectory };
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@lukstei/dsh-scratch-dir",
3
- "version": "0.2.2-rc.5.4",
3
+ "version": "0.2.2-rc.5.6",
4
4
  "description": "Scratch directory provisioner for DSH sessions",
5
5
  "type": "module",
6
- "main": "./src/index.ts",
6
+ "main": "./dist/index.js",
7
7
  "exports": {
8
- ".": "./src/index.ts"
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ }
9
12
  },
10
13
  "dsh": {
11
14
  "bundle": {
@@ -30,6 +33,7 @@
30
33
  },
31
34
  "files": [
32
35
  "src",
36
+ "dist",
33
37
  "README.md",
34
38
  "cordis.patch.yml",
35
39
  "!src/**/*.spec.*",
@@ -51,9 +55,11 @@
51
55
  "access": "public"
52
56
  },
53
57
  "scripts": {
58
+ "build": "tsdown --config tsdown.config.ts --logLevel error",
59
+ "dev": "tsdown --config tsdown.config.ts --watch",
54
60
  "check": "biome check --reporter=concise .",
55
61
  "typecheck": "tsc --noEmit",
56
62
  "test": "node --experimental-test-module-mocks --test --test-reporter=dot",
57
- "verify": "pnpm --silent run check && pnpm --silent run typecheck && pnpm --silent run test"
63
+ "verify": "pnpm --silent run check && pnpm --silent run build && pnpm --silent run typecheck && pnpm --silent run test"
58
64
  }
59
65
  }