@turingcode/cli 0.2.7 → 0.2.8
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/README.md +1 -1
- package/dist/core/files.js +2 -2
- package/dist/core/mcp.js +17 -10
- package/dist/features/contract/load.js +2 -2
- package/dist/features/tool/command.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ plus the operators below for references, exact numbers and checks across rows).
|
|
|
66
66
|
| `format` | `markdown` | `markdown`: each table under a `## <name>` heading. `csv`: `<name>.csv` files (pass the folder, or one file). |
|
|
67
67
|
| `missing_values` | `[""]` | Cell texts that count as empty (`null` in queries). Leave out a marker like `-` when it is a real value: "`-` allowed, empty forbidden" is `"required": true` with `"match": {"$or": [{"$eq": "-"}, ...]}`. |
|
|
68
68
|
| `allow_extra_tables` | `false` | Allow tables the contract does not declare. |
|
|
69
|
-
| `depends_on` | | `alias -> contract file
|
|
69
|
+
| `depends_on` | | `alias -> contract file` (absolute, or relative to this contract); its tables are passed with `--dep alias=<file>`. |
|
|
70
70
|
|
|
71
71
|
**Table**: `name` and `columns` are required.
|
|
72
72
|
|
package/dist/core/files.js
CHANGED
|
@@ -25,14 +25,14 @@ export function readJsonFile(path) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Reads a JSON flag: inline JSON
|
|
28
|
+
* Reads a JSON flag: inline JSON when it starts with `{` or `[`, otherwise a path to a .json file.
|
|
29
29
|
*
|
|
30
30
|
* @param {string} value - Raw flag value.
|
|
31
31
|
* @returns {unknown} The parsed JSON.
|
|
32
32
|
* @throws {Error} When the file cannot be read or the JSON is invalid.
|
|
33
33
|
*/
|
|
34
34
|
export function readJsonArg(value) {
|
|
35
|
-
const text = value
|
|
35
|
+
const text = /^\s*[{[]/.test(value) ? value : readFileSync(value, "utf-8");
|
|
36
36
|
try {
|
|
37
37
|
return JSON.parse(text);
|
|
38
38
|
}
|
package/dist/core/mcp.js
CHANGED
|
@@ -19,18 +19,25 @@ export const TOKEN_HELP = [
|
|
|
19
19
|
* @param {string} token - Bearer token for the gateway.
|
|
20
20
|
* @param {string} [url=DEFAULT_URL] - Gateway endpoint.
|
|
21
21
|
* @returns {Promise<any>} The reply's `result`.
|
|
22
|
-
* @throws {Error}
|
|
22
|
+
* @throws {Error} When the gateway cannot be reached, on HTTP errors, or on a JSON-RPC error reply.
|
|
23
23
|
*/
|
|
24
24
|
async function postGateway(method, params, token, url = DEFAULT_URL) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
let response;
|
|
26
|
+
try {
|
|
27
|
+
response = await fetch(url, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: {
|
|
30
|
+
"Authorization": `Bearer ${token}`,
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
"Accept": "application/json, text/event-stream",
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
const cause = e.cause;
|
|
39
|
+
throw new Error(`cannot reach the gateway at ${url}: ${cause?.code ?? cause?.message ?? e.message}`);
|
|
40
|
+
}
|
|
34
41
|
const body = await response.text();
|
|
35
42
|
if (!response.ok) {
|
|
36
43
|
throw new Error(`gateway HTTP ${response.status}: ${body.trim() || response.statusText}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { basename, dirname,
|
|
1
|
+
import { basename, dirname, resolve } from "node:path";
|
|
2
2
|
import { readJsonFile } from "../../core/files.js";
|
|
3
3
|
import { checkShape, show } from "../../core/json-shape.js";
|
|
4
4
|
import { diag } from "./diagnostics.js";
|
|
@@ -182,7 +182,7 @@ export function loadContract(path, out, stack = []) {
|
|
|
182
182
|
for (const [alias, rel] of Object.entries(dependsOn)) {
|
|
183
183
|
if (typeof rel !== "string")
|
|
184
184
|
continue; // reported by the shape check
|
|
185
|
-
const depPath =
|
|
185
|
+
const depPath = resolve(dirname(path), rel);
|
|
186
186
|
if ([...stack, full].includes(resolve(depPath))) {
|
|
187
187
|
own.push(diag("CONTRACT.CYCLE", `depends_on '${alias}' leads back to ${rel}`, { column: `depends_on.${alias}` }, rel, "no cycle"));
|
|
188
188
|
depsOk = false;
|
|
@@ -127,7 +127,7 @@ const call = {
|
|
|
127
127
|
.epilogue([
|
|
128
128
|
"Calls one tool of the Turing Code server. <name> comes from `tool list`, its arguments from",
|
|
129
129
|
"`tool describe <name>`.",
|
|
130
|
-
"--args is a JSON object: inline when it starts with `{`,",
|
|
130
|
+
"--args is a JSON object: inline when it starts with `{` or `[`,",
|
|
131
131
|
"otherwise a path to a .json file; leave it out for a tool without arguments.",
|
|
132
132
|
"The tool's text result goes to stdout: redirect it (`> file`) to save a large result without",
|
|
133
133
|
"reading it. A tool error is printed to stderr.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turingcode/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Turing Code toolkit for AI agents: check Markdown/CSV tables against table contracts, e.g. `turingcode table check`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
"@types/yargs": "17.0.35",
|
|
32
32
|
"typescript": "7.0.2"
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|