@vymalo/opencode-devtools 0.11.0 → 0.14.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.
@@ -3,97 +3,124 @@ import { JSONPath } from "jsonpath-plus";
3
3
  import Papa from "papaparse";
4
4
  import YAML from "yaml";
5
5
  import { json, reqString } from "../tool-spec.js";
6
- const FORMATS = ["json", "yaml", "toml", "csv"];
6
+ const FORMATS = [
7
+ "json",
8
+ "yaml",
9
+ "toml",
10
+ "csv"
11
+ ];
7
12
  function decode(input, format) {
8
- switch (format) {
9
- case "json":
10
- return JSON.parse(input);
11
- case "yaml":
12
- return YAML.parse(input);
13
- case "toml":
14
- return TOML.parse(input);
15
- case "csv": {
16
- // dynamicTyping is intentionally OFF: it would coerce "00123" → 123 (losing
17
- // leading zeros) and round 64-bit IDs, silently corrupting the data. Keep
18
- // every field as a string for a faithful conversion.
19
- const parsed = Papa.parse(input.trim(), {
20
- header: true,
21
- skipEmptyLines: true,
22
- dynamicTyping: false
23
- });
24
- if (parsed.errors.length > 0) {
25
- throw new Error(`CSV parse error: ${parsed.errors[0].message}`);
26
- }
27
- return parsed.data;
28
- }
29
- }
13
+ switch (format) {
14
+ case "json": return JSON.parse(input);
15
+ case "yaml": return YAML.parse(input);
16
+ case "toml": return TOML.parse(input);
17
+ case "csv": {
18
+ // dynamicTyping is intentionally OFF: it would coerce "00123" → 123 (losing
19
+ // leading zeros) and round 64-bit IDs, silently corrupting the data. Keep
20
+ // every field as a string for a faithful conversion.
21
+ const parsed = Papa.parse(input.trim(), {
22
+ header: true,
23
+ skipEmptyLines: true,
24
+ dynamicTyping: false
25
+ });
26
+ if (parsed.errors.length > 0) {
27
+ throw new Error(`CSV parse error: ${parsed.errors[0].message}`);
28
+ }
29
+ return parsed.data;
30
+ }
31
+ }
30
32
  }
31
33
  function encode(value, format) {
32
- switch (format) {
33
- case "json":
34
- return JSON.stringify(value, null, 2);
35
- case "yaml":
36
- return YAML.stringify(value);
37
- case "toml":
38
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
39
- throw new Error("TOML output requires a top-level object (table)");
40
- }
41
- return TOML.stringify(value);
42
- case "csv": {
43
- const rows = Array.isArray(value) ? value : [value];
44
- return Papa.unparse(rows);
45
- }
46
- }
34
+ switch (format) {
35
+ case "json": return JSON.stringify(value, null, 2);
36
+ case "yaml": return YAML.stringify(value);
37
+ case "toml":
38
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
39
+ throw new Error("TOML output requires a top-level object (table)");
40
+ }
41
+ return TOML.stringify(value);
42
+ case "csv": {
43
+ const rows = Array.isArray(value) ? value : [value];
44
+ return Papa.unparse(rows);
45
+ }
46
+ }
47
47
  }
48
- export const CONVERT_TOOLS = [
49
- {
50
- name: "convert_data",
51
- group: "convert",
52
- description: "Convert structured data between JSON, YAML, TOML and CSV. CSV maps to/from an array of row objects; TOML output needs a top-level object.",
53
- input: {
54
- input: { type: "string", description: "The source document." },
55
- from: { type: "string", enum: FORMATS, description: "Source format." },
56
- to: { type: "string", enum: FORMATS, description: "Target format." }
57
- },
58
- handler: (args) => {
59
- const input = reqString(args, "input");
60
- const from = reqString(args, "from");
61
- const to = reqString(args, "to");
62
- const value = decode(input, from);
63
- const out = encode(value, to);
64
- return json({ from, to, result: out }, out);
65
- }
66
- },
67
- {
68
- name: "convert_query",
69
- group: "convert",
70
- description: 'Run a JSONPath query against a JSON, YAML or TOML document and return the matching values. Example path: "$.items[*].name".',
71
- input: {
72
- input: { type: "string", description: "The source document." },
73
- path: { type: "string", description: 'JSONPath expression, e.g. "$.store.book[*].author".' },
74
- from: {
75
- type: "string",
76
- optional: true,
77
- enum: ["json", "yaml", "toml"],
78
- description: "Source format (default json)."
79
- }
80
- },
81
- handler: (args) => {
82
- const input = reqString(args, "input");
83
- const path = reqString(args, "path");
84
- const from = (typeof args.from === "string" ? args.from : "json");
85
- const value = decode(input, from);
86
- // eval: false disables script/filter expressions (`[?(...)]`) — they run
87
- // arbitrary JS via the engine. `path` is model-supplied, so this keeps the
88
- // tool deterministic (no sandbox escape). Standard path queries still work.
89
- const matches = JSONPath({
90
- path,
91
- json: value,
92
- wrap: true,
93
- eval: false
94
- });
95
- return json({ path, count: matches.length, matches }, matches.length === 0 ? "(no matches)" : JSON.stringify(matches, null, 2));
96
- }
97
- }
98
- ];
48
+ export const CONVERT_TOOLS = [{
49
+ name: "convert_data",
50
+ group: "convert",
51
+ description: "Convert structured data between JSON, YAML, TOML and CSV. CSV maps to/from an array of row objects; TOML output needs a top-level object.",
52
+ input: {
53
+ input: {
54
+ type: "string",
55
+ description: "The source document."
56
+ },
57
+ from: {
58
+ type: "string",
59
+ enum: FORMATS,
60
+ description: "Source format."
61
+ },
62
+ to: {
63
+ type: "string",
64
+ enum: FORMATS,
65
+ description: "Target format."
66
+ }
67
+ },
68
+ handler: (args) => {
69
+ const input = reqString(args, "input");
70
+ const from = reqString(args, "from");
71
+ const to = reqString(args, "to");
72
+ const value = decode(input, from);
73
+ const out = encode(value, to);
74
+ return json({
75
+ from,
76
+ to,
77
+ result: out
78
+ }, out);
79
+ }
80
+ }, {
81
+ name: "convert_query",
82
+ group: "convert",
83
+ description: "Run a JSONPath query against a JSON, YAML or TOML document and return the matching values. Example path: \"$.items[*].name\".",
84
+ input: {
85
+ input: {
86
+ type: "string",
87
+ description: "The source document."
88
+ },
89
+ path: {
90
+ type: "string",
91
+ description: "JSONPath expression, e.g. \"$.store.book[*].author\"."
92
+ },
93
+ from: {
94
+ type: "string",
95
+ optional: true,
96
+ enum: [
97
+ "json",
98
+ "yaml",
99
+ "toml"
100
+ ],
101
+ description: "Source format (default json)."
102
+ }
103
+ },
104
+ handler: (args) => {
105
+ const input = reqString(args, "input");
106
+ const path = reqString(args, "path");
107
+ const from = typeof args.from === "string" ? args.from : "json";
108
+ const value = decode(input, from);
109
+ // eval: false disables script/filter expressions (`[?(...)]`) — they run
110
+ // arbitrary JS via the engine. `path` is model-supplied, so this keeps the
111
+ // tool deterministic (no sandbox escape). Standard path queries still work.
112
+ const matches = JSONPath({
113
+ path,
114
+ json: value,
115
+ wrap: true,
116
+ eval: false
117
+ });
118
+ return json({
119
+ path,
120
+ count: matches.length,
121
+ matches
122
+ }, matches.length === 0 ? "(no matches)" : JSON.stringify(matches, null, 2));
123
+ }
124
+ }];
125
+
99
126
  //# sourceMappingURL=convert.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/groups/convert.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAiB,MAAM,iBAAiB,CAAC;AAGjE,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAU,CAAC;AAEzD,SAAS,MAAM,CAAC,KAAa,EAAE,MAAc;IAC3C,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,4EAA4E;YAC5E,0EAA0E;YAC1E,qDAAqD;YACrD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE;gBACtC,MAAM,EAAE,IAAI;gBACZ,cAAc,EAAE,IAAI;gBACpB,aAAa,EAAE,KAAK;aACrB,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7B,MA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