@opencode/codemode 0.0.0-dev-19583 → 0.0.0-dev-19585

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/dist/data.d.ts CHANGED
@@ -23,4 +23,4 @@ export declare const fromData: (protos: Prototypes, value: unknown, label: strin
23
23
  * dropped ("json") or become null ("result", for program results where the consumer must never see
24
24
  * undefined); a bare `undefined` follows the same rule.
25
25
  */
26
- export declare const toData: (value: unknown, label: string, undefinedAs?: "json" | "result") => unknown;
26
+ export declare const toData: (value: unknown, label: string, undefinedAs?: "json" | "result", stripProto?: boolean) => unknown;
package/dist/data.js CHANGED
@@ -28,9 +28,9 @@ export const fromData = (protos, value, label) => copy(value, label, "data", 0,
28
28
  * dropped ("json") or become null ("result", for program results where the consumer must never see
29
29
  * undefined); a bare `undefined` follows the same rule.
30
30
  */
31
- export const toData = (value, label, undefinedAs = "json") => copy(value, label, undefinedAs, 0, new Set());
32
- const copy = (value, label, mode, depth, seen, protos) => {
33
- const next = (item) => copy(item, label, mode, depth + 1, seen, protos);
31
+ export const toData = (value, label, undefinedAs = "json", stripProto = true) => copy(value, label, undefinedAs, 0, new Set(), undefined, stripProto);
32
+ const copy = (value, label, mode, depth, seen, protos, stripProto = true) => {
33
+ const next = (item) => copy(item, label, mode, depth + 1, seen, protos, stripProto);
34
34
  if (depth > MAX_VALUE_DEPTH) {
35
35
  throw new ToolRuntimeError("InvalidDataValue", `${label} exceeds the maximum value depth of ${MAX_VALUE_DEPTH}.`);
36
36
  }
@@ -106,6 +106,8 @@ const copy = (value, label, mode, depth, seen, protos) => {
106
106
  defineHost(copied, "message", next(get(value, "message")));
107
107
  }
108
108
  for (const [key, item] of entries(value)) {
109
+ if (stripProto && key === "__proto__")
110
+ continue;
109
111
  const copiedItem = next(item);
110
112
  if (copiedItem === undefined && mode === "json")
111
113
  continue;
@@ -141,6 +143,8 @@ const copy = (value, label, mode, depth, seen, protos) => {
141
143
  }
142
144
  const copied = {};
143
145
  for (const [key, item] of Object.entries(value)) {
146
+ if (stripProto && key === "__proto__")
147
+ continue;
144
148
  const copiedItem = next(item);
145
149
  if (copiedItem === undefined && mode === "json")
146
150
  continue;
@@ -53,7 +53,8 @@ const stringify = (runner, args) => {
53
53
  .filter((item) => typeof item === "string" || typeof item === "number")
54
54
  .map(String)
55
55
  : null;
56
- return Effect.succeed(JSON.stringify(toData(args[0], "JSON.stringify value"), properties, indent));
56
+ // A string cannot pollute, so __proto__ stays: JSON.stringify includes own __proto__ keys, like JS.
57
+ return Effect.succeed(JSON.stringify(toData(args[0], "JSON.stringify value", "json", false), properties, indent));
57
58
  }
58
59
  // Validate up front; the replacer walk below reads the original value.
59
60
  toProgram(runner.prototypes, args[0], "JSON.stringify value");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/codemode",
4
- "version": "0.0.0-dev-19583",
4
+ "version": "0.0.0-dev-19585",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",