dsh-openwrite 0.2.26 → 0.2.28

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 (37) hide show
  1. package/README.md +16 -4
  2. package/docs/CLOSED_ISSUE_FOLLOWUPS.md +35 -0
  3. package/docs/CONTEXT_SLOTS.md +60 -0
  4. package/docs/EDITOR_SAFETY_REPAIRS.md +17 -0
  5. package/docs/ISSUES_105_113.md +4 -1
  6. package/docs/ISSUES_121_123.md +97 -0
  7. package/docs/ISSUES_98_100.md +2 -0
  8. package/docs/ISSUE_123_FOLLOWUP.md +54 -0
  9. package/docs/OPENCODE_GO.md +24 -18
  10. package/docs/RELEASE_ACCEPTANCE.md +89 -1
  11. package/docs/SELECTION_UPGRADE_REPAIRS.md +16 -0
  12. package/docs/TOOLS.md +1356 -0
  13. package/dog-tools.mjs +5 -3
  14. package/package.json +5 -4
  15. package/packages/openwrite-bridge/lib/contracts-generated.js +9 -0
  16. package/packages/openwrite-bridge/lib/dog-delivery.js +7 -3
  17. package/packages/openwrite-bridge/lib/managed-runtime.d.ts +1 -0
  18. package/packages/openwrite-bridge/lib/managed-runtime.js +22 -2
  19. package/packages/openwrite-bridge/lib/tool-policy.js +2 -0
  20. package/packages/openwrite-bridge/lib/tools.js +28 -5
  21. package/packages/studio-panel/lib/client.js +821 -544
  22. package/packages/studio-panel/lib/client.js.map +1 -1
  23. package/packages/studio-panel/lib/types/client/VditorBody.d.ts +7 -1
  24. package/packages/studio-panel/lib/types/client/dto.d.ts +2 -0
  25. package/packages/studio-panel/lib/types/client/locales.d.ts +1 -1
  26. package/packages/studio-panel/lib/types/client/manuscript-annotations.d.ts +2 -1
  27. package/packages/studio-panel/lib/types/client/manuscript-overlay.d.ts +2 -1
  28. package/packages/studio-panel/lib/types/client/manuscript-selection.d.ts +18 -5
  29. package/packages/studio-panel/lib/types/client/selection-coordinates.d.ts +15 -0
  30. package/preset-definition.mjs +1 -1
  31. package/release/{openwrite-5.8.14-py3-none-any.whl → openwrite-5.8.20-py3-none-any.whl} +0 -0
  32. package/release/runtime-manifest.json +6 -5
  33. package/release/source.json +3 -3
  34. package/scripts/safe-upgrade.mjs +104 -9
  35. package/vendor/dsh-dog/lib/{core-BAlgZpLq.js → core--byUPJL8.js} +129 -12
  36. package/vendor/dsh-dog/lib/core.js +1 -1
  37. package/vendor/dsh-dog/lib/index.js +54 -103
@@ -1,12 +1,138 @@
1
+ import { spawn } from "node:child_process";
2
+ import { appendFile, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
1
3
  import { fileURLToPath } from "node:url";
2
4
  import { tmpdir } from "node:os";
3
5
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
- import { appendFile, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
5
6
  import { createHash, randomUUID } from "node:crypto";
6
7
  import { existsSync, readFileSync, readdirSync } from "node:fs";
7
8
  import { c } from "tar";
8
9
  import Ajv2020 from "ajv/dist/2020.js";
9
10
  import addFormats from "ajv-formats";
11
+ //#region src/owned-script.ts
12
+ var ScriptExecutionError = class extends Error {
13
+ code;
14
+ diagnostics;
15
+ constructor(code, message, diagnostics) {
16
+ super(message);
17
+ this.code = code;
18
+ this.diagnostics = diagnostics;
19
+ this.name = "ScriptExecutionError";
20
+ }
21
+ };
22
+ function outputPreview(output) {
23
+ return new TextDecoder().decode(Buffer.from(output).subarray(0, 200), { stream: true });
24
+ }
25
+ /** Execute without blocking the host event loop; cancellation owns only this process tree. */
26
+ async function runOwnedScript(script, input, signal) {
27
+ signal?.throwIfAborted();
28
+ try {
29
+ if (!(await stat(script)).isFile()) throw new Error("not a file");
30
+ } catch {
31
+ throw new ScriptExecutionError("SCRIPT_NOT_FOUND", `Verifier script was not found: ${script}`, { script });
32
+ }
33
+ signal?.throwIfAborted();
34
+ const js = /\.(?:c|m)?js$/.test(script);
35
+ const child = spawn(js ? process.execPath : script, js ? [script, input] : [input], {
36
+ detached: process.platform !== "win32",
37
+ windowsHide: true,
38
+ stdio: [
39
+ "ignore",
40
+ "pipe",
41
+ "pipe"
42
+ ],
43
+ env: js ? {
44
+ ...process.env,
45
+ ELECTRON_RUN_AS_NODE: "1"
46
+ } : process.env
47
+ });
48
+ let output = "";
49
+ let stderr = "";
50
+ let failure;
51
+ let escalation;
52
+ child.stdout.setEncoding("utf8");
53
+ child.stderr.setEncoding("utf8");
54
+ const stop = () => {
55
+ if (!child.pid || child.exitCode !== null || child.signalCode !== null) return;
56
+ if (process.platform === "win32") spawn("taskkill", [
57
+ "/pid",
58
+ String(child.pid),
59
+ "/T",
60
+ "/F"
61
+ ], {
62
+ windowsHide: true,
63
+ stdio: "ignore"
64
+ }).once("error", () => child.kill());
65
+ else {
66
+ try {
67
+ process.kill(-child.pid, "SIGTERM");
68
+ } catch {
69
+ child.kill();
70
+ }
71
+ escalation ??= setTimeout(() => {
72
+ if (child.exitCode !== null || child.signalCode !== null) return;
73
+ try {
74
+ process.kill(-child.pid, "SIGKILL");
75
+ } catch {
76
+ child.kill("SIGKILL");
77
+ }
78
+ }, 3e3);
79
+ }
80
+ };
81
+ child.stdout.on("data", (chunk) => {
82
+ output += String(chunk);
83
+ if (Buffer.byteLength(output) > 32 * 1024 ** 2) {
84
+ output = outputPreview(output);
85
+ failure = new ScriptExecutionError("SCRIPT_OUTPUT_LIMIT", "Verifier output exceeds limit", { script });
86
+ stop();
87
+ }
88
+ });
89
+ child.stderr.on("data", (chunk) => {
90
+ stderr = Buffer.concat([Buffer.from(stderr), Buffer.from(chunk)]).subarray(-4096).toString("utf8");
91
+ });
92
+ signal?.addEventListener("abort", stop, { once: true });
93
+ const timer = setTimeout(() => {
94
+ failure = new ScriptExecutionError("SCRIPT_TIMEOUT", "Verifier timed out", { script });
95
+ stop();
96
+ }, 9e5);
97
+ try {
98
+ if (signal?.aborted) stop();
99
+ await new Promise((done, reject) => {
100
+ child.once("error", (error) => reject(new ScriptExecutionError("SCRIPT_START_FAILED", `Could not start verifier: ${error.message}`, {
101
+ script,
102
+ stderr,
103
+ outputPreview: outputPreview(output)
104
+ })));
105
+ child.once("close", (code, exitSignal) => {
106
+ const diagnostics = {
107
+ script,
108
+ exitCode: code,
109
+ signal: exitSignal,
110
+ stderr,
111
+ outputPreview: outputPreview(output)
112
+ };
113
+ if (failure instanceof ScriptExecutionError) Object.assign(failure.diagnostics, diagnostics);
114
+ code === 0 ? done() : reject(failure ?? new ScriptExecutionError("SCRIPT_EXIT_FAILED", `Verifier exited (${code ?? exitSignal})`, diagnostics));
115
+ });
116
+ });
117
+ signal?.throwIfAborted();
118
+ if (failure) throw failure;
119
+ return output;
120
+ } finally {
121
+ clearTimeout(timer);
122
+ if (escalation) clearTimeout(escalation);
123
+ signal?.removeEventListener("abort", stop);
124
+ }
125
+ }
126
+ //#endregion
127
+ //#region src/model.ts
128
+ function isJsonValue(value) {
129
+ if (value === null || typeof value === "string" || typeof value === "boolean") return true;
130
+ if (typeof value === "number") return Number.isFinite(value);
131
+ if (Array.isArray(value)) return value.every(isJsonValue);
132
+ if (typeof value !== "object") return false;
133
+ return Object.values(value).every(isJsonValue);
134
+ }
135
+ //#endregion
10
136
  //#region src/logic.ts
11
137
  /**
12
138
  * Parse and type-check the only expression language accepted by DoG.
@@ -169,15 +295,6 @@ function isRecord(value) {
169
295
  return value !== null && typeof value === "object" && !Array.isArray(value);
170
296
  }
171
297
  //#endregion
172
- //#region src/model.ts
173
- function isJsonValue(value) {
174
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
175
- if (typeof value === "number") return Number.isFinite(value);
176
- if (Array.isArray(value)) return value.every(isJsonValue);
177
- if (typeof value !== "object") return false;
178
- return Object.values(value).every(isJsonValue);
179
- }
180
- //#endregion
181
298
  //#region src/graph.ts
182
299
  /** Graph parser, structural validator, and cycle checker for DoG v0.2. */
183
300
  const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
@@ -1935,7 +2052,7 @@ function resolveScriptPath(scriptsDirectory, script) {
1935
2052
  const withJs = `${direct}.js`;
1936
2053
  if (existsSync(withJs)) return withJs;
1937
2054
  }
1938
- throw new Error(`programmatic script not found in library: ${direct}`);
2055
+ throw new ScriptExecutionError("SCRIPT_NOT_FOUND", `programmatic script not found in library: ${direct}`, { script: direct });
1939
2056
  }
1940
2057
  function readScriptDigest(scriptPath) {
1941
2058
  try {
@@ -2071,4 +2188,4 @@ function hasTraversal(value) {
2071
2188
  return value.split(/[\\/]/u).some((segment) => segment === ".." || segment === ".");
2072
2189
  }
2073
2190
  //#endregion
2074
- export { DogRepository as a, parseGraph as c, parseBoolExpr as d, runPlan as i, isJsonValue as l, resolveScriptPath as n, loadSchemaSet as o, WorkspaceManager as r, DogValidationError as s, DogEngine as t, evaluateBoolExpr as u };
2191
+ export { DogRepository as a, parseGraph as c, isJsonValue as d, ScriptExecutionError as f, runPlan as i, evaluateBoolExpr as l, runOwnedScript as m, resolveScriptPath as n, loadSchemaSet as o, outputPreview as p, WorkspaceManager as r, DogValidationError as s, DogEngine as t, parseBoolExpr as u };
@@ -1,2 +1,2 @@
1
- import { n as resolveScriptPath, t as DogEngine } from "./core-BAlgZpLq.js";
1
+ import { n as resolveScriptPath, t as DogEngine } from "./core--byUPJL8.js";
2
2
  export { DogEngine, resolveScriptPath };
@@ -1,81 +1,64 @@
1
- import { a as DogRepository, c as parseGraph, d as parseBoolExpr, i as runPlan, l as isJsonValue, n as resolveScriptPath, o as loadSchemaSet, r as WorkspaceManager, s as DogValidationError, t as DogEngine, u as evaluateBoolExpr } from "./core-BAlgZpLq.js";
2
- import { spawn } from "node:child_process";
1
+ import { a as DogRepository, c as parseGraph, d as isJsonValue, f as ScriptExecutionError, i as runPlan, l as evaluateBoolExpr, m as runOwnedScript, n as resolveScriptPath, o as loadSchemaSet, p as outputPreview, r as WorkspaceManager, s as DogValidationError, t as DogEngine, u as parseBoolExpr } from "./core--byUPJL8.js";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { homedir } from "node:os";
5
5
  import { isAbsolute, join, resolve } from "node:path";
6
- import { mkdir, readFile, writeFile } from "node:fs/promises";
7
6
  import z from "@deepseek-ai/schemastery";
8
- //#region src/owned-script.ts
9
- /** Execute without blocking the host event loop; cancellation owns only this process tree. */
10
- async function runOwnedScript(script, input, signal) {
11
- signal?.throwIfAborted();
12
- const js = /\.(?:c|m)?js$/.test(script);
13
- const child = spawn(js ? process.execPath : script, js ? [script, input] : [input], {
14
- detached: process.platform !== "win32",
15
- windowsHide: true,
16
- stdio: [
17
- "ignore",
18
- "pipe",
19
- "pipe"
20
- ]
21
- });
22
- let output = "";
23
- let failure;
24
- let escalation;
25
- const stop = () => {
26
- if (!child.pid || child.exitCode !== null || child.signalCode !== null) return;
27
- if (process.platform === "win32") spawn("taskkill", [
28
- "/pid",
29
- String(child.pid),
30
- "/T",
31
- "/F"
32
- ], {
33
- windowsHide: true,
34
- stdio: "ignore"
35
- }).once("error", () => child.kill());
36
- else {
37
- try {
38
- process.kill(-child.pid, "SIGTERM");
39
- } catch {
40
- child.kill();
41
- }
42
- escalation ??= setTimeout(() => {
43
- if (child.exitCode !== null || child.signalCode !== null) return;
44
- try {
45
- process.kill(-child.pid, "SIGKILL");
46
- } catch {
47
- child.kill("SIGKILL");
48
- }
49
- }, 3e3);
7
+ //#region src/script-verdict.ts
8
+ function scriptFailureVerdict(error) {
9
+ const message = error instanceof Error ? error.message : String(error);
10
+ return {
11
+ state: "inconclusive",
12
+ reason: message,
13
+ evidence: error instanceof ScriptExecutionError ? {
14
+ code: error.code,
15
+ error: message,
16
+ ...error.diagnostics
17
+ } : {
18
+ code: "SCRIPT_EXECUTION_FAILED",
19
+ error: message
50
20
  }
51
21
  };
52
- child.stdout.on("data", (chunk) => {
53
- output += String(chunk);
54
- if (Buffer.byteLength(output) > 32 * 1024 ** 2) {
55
- failure = /* @__PURE__ */ new Error("verifier output exceeds limit");
56
- stop();
57
- }
58
- });
59
- child.stderr.resume();
60
- signal?.addEventListener("abort", stop, { once: true });
61
- const timer = setTimeout(() => {
62
- failure = /* @__PURE__ */ new Error("verifier timeout");
63
- stop();
64
- }, 9e5);
22
+ }
23
+ function parseVerdict(out) {
24
+ let value;
65
25
  try {
66
- if (signal?.aborted) stop();
67
- await new Promise((done, reject) => {
68
- child.once("error", reject);
69
- child.once("close", (code) => code === 0 ? done() : reject(failure ?? /* @__PURE__ */ new Error(`verifier exited (${code})`)));
70
- });
71
- signal?.throwIfAborted();
72
- if (failure) throw failure;
73
- return output;
74
- } finally {
75
- clearTimeout(timer);
76
- if (escalation) clearTimeout(escalation);
77
- signal?.removeEventListener("abort", stop);
26
+ value = JSON.parse(out);
27
+ } catch {
28
+ return {
29
+ state: "inconclusive",
30
+ evidence: {
31
+ code: "SCRIPT_OUTPUT_NOT_JSON",
32
+ parseError: "script output was not JSON",
33
+ outputPreview: outputPreview(out)
34
+ },
35
+ reason: "script output was not JSON"
36
+ };
78
37
  }
38
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return {
39
+ state: "inconclusive",
40
+ evidence: {
41
+ code: "SCRIPT_OUTPUT_INVALID",
42
+ parseError: "script output was not an object",
43
+ outputPreview: outputPreview(out)
44
+ },
45
+ reason: "script output was not an object"
46
+ };
47
+ const record = value;
48
+ const verdict = record.verdict;
49
+ if (verdict !== "pass" && verdict !== "fail" && verdict !== "inconclusive") return {
50
+ state: "inconclusive",
51
+ evidence: {
52
+ code: "SCRIPT_OUTPUT_INVALID",
53
+ parseError: "invalid verdict",
54
+ outputPreview: outputPreview(out)
55
+ },
56
+ reason: "script returned an invalid verdict"
57
+ };
58
+ return {
59
+ state: verdict,
60
+ evidence: isJsonValue(record.evidence) ? record.evidence : { outcome: "no evidence supplied by script" }
61
+ };
79
62
  }
80
63
  //#endregion
81
64
  //#region src/host-shims.ts
@@ -1041,11 +1024,7 @@ async function apply(ctx, config) {
1041
1024
  try {
1042
1025
  out = await runOwnedScript(resolveScriptPath(scriptsDir, script), inputPath, env.signal);
1043
1026
  } catch (error) {
1044
- return {
1045
- state: "inconclusive",
1046
- evidence: { error: String(error instanceof Error ? error.message : error) },
1047
- reason: "script execution failed"
1048
- };
1027
+ return scriptFailureVerdict(error);
1049
1028
  }
1050
1029
  return parseVerdict(out);
1051
1030
  };
@@ -1236,34 +1215,6 @@ function buildVerifierPrompt(instruction, inputPath, resultPath) {
1236
1215
  "Create it (it does not exist yet); never write it as a relative path or to another location. After writing, stop."
1237
1216
  ].join("\n");
1238
1217
  }
1239
- function parseVerdict(out) {
1240
- let value;
1241
- try {
1242
- value = JSON.parse(out);
1243
- } catch {
1244
- return {
1245
- state: "inconclusive",
1246
- evidence: { parseError: "script output was not JSON" },
1247
- reason: "script output was not JSON"
1248
- };
1249
- }
1250
- const record = value;
1251
- if (record === null || typeof record !== "object" || Array.isArray(record)) return {
1252
- state: "inconclusive",
1253
- evidence: { parseError: "script output was not an object" },
1254
- reason: "script output was not an object"
1255
- };
1256
- const verdict = record.verdict;
1257
- if (verdict !== "pass" && verdict !== "fail" && verdict !== "inconclusive") return {
1258
- state: "inconclusive",
1259
- evidence: { parseError: "invalid verdict" },
1260
- reason: "script returned an invalid verdict"
1261
- };
1262
- return {
1263
- state: verdict,
1264
- evidence: isJsonValue(record.evidence) ? record.evidence : { outcome: "no evidence supplied by script" }
1265
- };
1266
- }
1267
1218
  /** Read the durable session id from a live Agent, or '' outside an agent boundary. */
1268
1219
  function readSessionId(parent) {
1269
1220
  if (parent === void 0) return "";