@lmctl-ai/lmctl 0.2.110 → 0.2.112

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.
@@ -4,31 +4,29 @@
4
4
  # import them. The engine owns lmctl's own internals as host functions; everything external is
5
5
  # user space -- the same pattern applies to gh, aws, or any other CLI a script wants to wrap.
6
6
 
7
- # NOTE: system() goes through a SHELL and there is no quoting helper, so any subcmd containing
8
- # | & ; < > $ ` must be quoted by the caller. The failure mode is an EMPTY result, not an error --
9
- # `--pretty=format:%h|%s` silently pipes into `%s` and returns "".
10
- # NOTE: system() returns [stdout, stderr] and NO exit status, so these wrappers cannot distinguish
11
- # "command failed" from "command succeeded with no output".
7
+ # Argv stays structured; failures name git and include its stderr.
12
8
  fn git_run(repo, subcmd) {
13
- out = system(format("git -C {0} {1} 2>/dev/null", repo, subcmd));
9
+ out = system(concat(["git", "-C", repo], subcmd));
10
+ if (out.code != 0) { require(false, "git failed (" + str(out.code) + "): " + out.stderr); }
14
11
  return trim(out.stdout);
15
12
  }
16
13
 
17
14
  fn is_git_repo(path) {
18
15
  if (!file_exists(path)) { return false; }
19
- return git_run(path, "rev-parse --is-inside-work-tree") == "true";
16
+ r = system(["git","-C",path,"rev-parse","--is-inside-work-tree"]);
17
+ return r.code == 0 && trim(r.stdout) == "true";
20
18
  }
21
19
 
22
20
  fn git_head(repo) {
23
- return git_run(repo, "log -1 --format=%H");
21
+ return git_run(repo, ["log", "-1", "--format=%H"]);
24
22
  }
25
23
 
26
24
  fn git_head_short(repo) {
27
- return git_run(repo, "log -1 --pretty=format:%h|%s"); # no space: git_run does not quote
25
+ return git_run(repo, ["log", "-1", "--pretty=format:%h|%s"]); # format is one argv element
28
26
  }
29
27
 
30
28
  fn git_head_epoch(repo) {
31
- s = git_run(repo, "log -1 --format=%ct");
29
+ s = git_run(repo, ["log", "-1", "--format=%ct"]);
32
30
  if (len(s) == 0) { return 0; }
33
31
  return num(s);
34
32
  }
@@ -36,7 +34,7 @@ fn git_head_epoch(repo) {
36
34
  # Changed = tracked-but-modified. Untracked = new and unignored. Kept separate on purpose:
37
35
  # conflating them is how "the tree is dirty" stops telling you WHICH kind of dirty.
38
36
  fn git_changed(repo) {
39
- lines = split(git_run(repo, "status --porcelain"), "\n");
37
+ lines = split(git_run(repo, ["status", "--porcelain"]), "\n");
40
38
  changed = [];
41
39
  i = 0;
42
40
  while (i < len(lines)) {
@@ -48,7 +46,7 @@ fn git_changed(repo) {
48
46
  }
49
47
 
50
48
  fn git_untracked(repo) {
51
- lines = split(git_run(repo, "status --porcelain"), "\n");
49
+ lines = split(git_run(repo, ["status", "--porcelain"]), "\n");
52
50
  untracked = [];
53
51
  i = 0;
54
52
  while (i < len(lines)) {
@@ -61,9 +59,9 @@ fn git_untracked(repo) {
61
59
  fn git_unpushed(repo) {
62
60
  # No upstream is NOT an error -- a worktree branch deliberately has none.
63
61
  # NOTE: "@{u}" cannot go through format() -- "{u}" is read as a format placeholder.
64
- up = system("git -C " + repo + " rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null");
62
+ up = system(["git","-C",repo,"rev-parse","--abbrev-ref","--symbolic-full-name","@{u}"]);
65
63
  if (len(trim(up.stdout)) == 0) { return -1; } # -1 = no upstream, distinct from 0 = nothing to push
66
- n = trim(system("git -C " + repo + " rev-list --count @{u}..HEAD 2>/dev/null").stdout);
64
+ n = trim(system(["git","-C",repo,"rev-list","--count","@{u}..HEAD"]).stdout);
67
65
  if (len(n) == 0) { return -1; }
68
66
  return num(n);
69
67
  }
@@ -71,7 +69,7 @@ fn git_unpushed(repo) {
71
69
  # "Are these changes AFTER some LLM process?" -- compare the working tree's newest mtime against a
72
70
  # marker time (e.g. when an agent turn started).
73
71
  fn touched_since(repo, epoch) {
74
- out = system(format("git -C {0} status --porcelain", repo));
72
+ out = system(["git","-C",repo,"status","--porcelain"]);
75
73
  lines = split(trim(out.stdout), "\n");
76
74
  recent = [];
77
75
  i = 0;
@@ -80,7 +78,7 @@ fn touched_since(repo, epoch) {
80
78
  if (len(l) == 0) { continue; }
81
79
  parts = split(l, " ");
82
80
  f = parts[len(parts) - 1];
83
- st = system(format("stat -c %Y {0}/{1} 2>/dev/null", repo, f));
81
+ st = system(["stat","-c","%Y",path_join(repo,f)]);
84
82
  m = trim(st.stdout);
85
83
  if (len(m) > 0 && num(m) >= epoch) { push(recent, f); }
86
84
  }
@@ -9,18 +9,18 @@ import "./agent-lib.lms";
9
9
  # --- External Service Wrappers over system() ---
10
10
 
11
11
  fn curl_fetch_json(url) {
12
- cmd = format("curl -s -m 10 \"{0}\"", url);
13
- out = system(cmd);
14
- if (out[2] != 0 || len(trim(out[0])) == 0) {
12
+ argv = ["curl","-s","-m","10",url];
13
+ out = system(argv);
14
+ if (out.code != 0 || len(trim(out.stdout)) == 0) {
15
15
  return null;
16
16
  }
17
- return json_parse(trim(out[0]));
17
+ return json_parse(trim(out.stdout));
18
18
  }
19
19
 
20
20
  fn curl_post_webhook(url, body_json) {
21
- cmd = format("curl -s -o /dev/null -w \"%{http_code}\" -m 10 -X POST -H \"Content-Type: application/json\" -d '{0}' \"{1}\"", body_json, url);
22
- out = system(cmd);
23
- return trim(out[0]);
21
+ argv = ["curl","-s","-o","/dev/null","-w","%{http_code}","-m","10","-X","POST","-H","Content-Type: application/json","-d",body_json,url];
22
+ out = system(argv);
23
+ return trim(out.stdout);
24
24
  }
25
25
 
26
26
  # --- Main Script ---
@@ -16,14 +16,14 @@ fn curl_get_openai_embedding(text, api_key) {
16
16
  "input": text,
17
17
  "model": "text-embedding-3-small"
18
18
  });
19
- cmd = format("curl -s https://api.openai.com/v1/embeddings -H \"Authorization: Bearer {0}\" -H \"Content-Type: application/json\" -d '{1}'", api_key, payload);
20
- out = system(cmd, 15000);
21
- if (out[2] != 0 || len(trim(out[0])) == 0) {
22
- return { "error": "CURL_FAILED", "details": trim(out[1]), "vector": [] };
19
+ argv = ["curl","-s","https://api.openai.com/v1/embeddings","-H","Authorization: Bearer "+api_key,"-H","Content-Type: application/json","-d",payload];
20
+ out = system(argv, 15000);
21
+ if (out.code != 0 || len(trim(out.stdout)) == 0) {
22
+ return { "error": "CURL_FAILED", "details": trim(out.stderr), "vector": [] };
23
23
  }
24
- res = json_parse(trim(out[0]));
24
+ res = json_parse(trim(out.stdout));
25
25
  if (res == null || !has_key(res, "data")) {
26
- return { "error": "API_ERROR", "details": trim(out[0]), "vector": [] };
26
+ return { "error": "API_ERROR", "details": trim(out.stdout), "vector": [] };
27
27
  }
28
28
  return { "error": null, "vector": res.data[0].embedding };
29
29
  }
@@ -66,7 +66,7 @@ if (len(args) > 1) { alias = args[1]; }
66
66
 
67
67
  # Check for API key in environment
68
68
  api_key = "";
69
- env_key = system("echo -n \"$OPENAI_API_KEY\"");
69
+ env_key = {stdout: env("OPENAI_API_KEY", "")};
70
70
  if (len(trim(env_key[0])) > 0) {
71
71
  api_key = trim(env_key[0]);
72
72
  }
@@ -9,24 +9,24 @@ import "./agent-lib.lms";
9
9
  # --- External Tool Wrappers over system() ---
10
10
 
11
11
  fn tool_sqlite_query(db_path, sql) {
12
- cmd = format("sqlite3 -batch -json \"{0}\" \"{1}\" 2>&1", db_path, sql);
13
- out = system(cmd);
14
- if (out[2] != 0) {
15
- return "Error executing query: " + trim(out[1]);
12
+ argv = ["sqlite3","-batch","-json",db_path,sql];
13
+ out = system(argv);
14
+ if (out.code != 0) {
15
+ return "Error executing query: " + trim(out.stderr);
16
16
  }
17
- return trim(out[0]);
17
+ return trim(out.stdout);
18
18
  }
19
19
 
20
20
  fn tool_search_kb(keyword, doc_dir) {
21
- cmd = format("grep -rn -i -m 5 \"{0}\" \"{1}\" 2>/dev/null", keyword, doc_dir);
22
- out = system(cmd);
23
- return trim(out[0]);
21
+ argv = ["grep","-rn","-i","-m","5","--",keyword,doc_dir];
22
+ out = system(argv);
23
+ return trim(out.stdout);
24
24
  }
25
25
 
26
26
  fn tool_http_ping(host) {
27
- cmd = format("curl -s -o /dev/null -w \"%{http_code}\" --connect-timeout 2 \"{0}\"", host);
28
- out = system(cmd);
29
- return trim(out[0]);
27
+ argv = ["curl","-s","-o","/dev/null","-w","%{http_code}","--connect-timeout","2",host];
28
+ out = system(argv);
29
+ return trim(out.stdout);
30
30
  }
31
31
 
32
32
  # --- Setup Mock Environment for the Agent's Tools ---
@@ -36,7 +36,7 @@ mock_db = "examples/n8n/mock-support.db";
36
36
  init_sql = "CREATE TABLE IF NOT EXISTS orders (order_id TEXT PRIMARY KEY, customer_id TEXT, status TEXT, total REAL, item TEXT);" +
37
37
  "INSERT OR REPLACE INTO orders VALUES ('ORD-9021', 'CUST-104', 'Shipped - In Transit', 85.00, 'Mechanical Keyboard');" +
38
38
  "INSERT OR REPLACE INTO orders VALUES ('ORD-9022', 'CUST-208', 'Pending Fulfillment', 24.50, 'USB-C Cable Pack');";
39
- system(format("sqlite3 \"{0}\" \"{1}\"", mock_db, init_sql));
39
+ system(["sqlite3",mock_db,init_sql]);
40
40
 
41
41
  # --- Main Script ---
42
42
 
@@ -9,15 +9,15 @@ import "./agent-lib.lms";
9
9
  # --- External Service Wrappers over system() ---
10
10
 
11
11
  fn gh_create_issue(repo, title, body, label) {
12
- cmd = format("gh issue create -R \"{0}\" --title \"{1}\" --body \"{2}\" --label \"{3}\" 2>&1", repo, title, body, label);
13
- out = system(cmd);
14
- return [out[2], trim(out[0])];
12
+ argv = ["gh","issue","create","-R",repo,"--title",title,"--body",body,"--label",label];
13
+ out = system(argv);
14
+ return [out.code, trim(out.stdout)];
15
15
  }
16
16
 
17
17
  fn post_webhook(url, payload_json) {
18
- cmd = format("curl -s -o /dev/null -w \"%{http_code}\" -X POST -H \"Content-Type: application/json\" -d '{0}' \"{1}\"", payload_json, url);
19
- out = system(cmd);
20
- return trim(out[0]);
18
+ argv = ["curl","-s","-o","/dev/null","-w","%{http_code}","-X","POST","-H","Content-Type: application/json","-d",payload_json,url];
19
+ out = system(argv);
20
+ return trim(out.stdout);
21
21
  }
22
22
 
23
23
  fn append_triage_log(log_path, record_json) {
package/modules/gh.lms ADDED
@@ -0,0 +1,68 @@
1
+ // GitHub GraphQL CLI wrapper; import declares functions only.
2
+ // gh.gh_graphql(query, vars) returns the parsed response map.
3
+ // Strings use raw -f; null/booleans/safe integers use -F. No floats,
4
+ // compound variables, pagination, schema lint or JSON-body transport.
5
+ // gh owns authentication/host configuration. All execution is argv, no shell.
6
+ // Completed failures and GraphQL errors stop with require (exit 2), naming
7
+ // gh api graphql and stderr tail/messages. Missing executable and invalid JSON
8
+ // remain located native errors (exit 1); no synthetic child exit is invented.
9
+ package gh;
10
+
11
+ fn _text(value, label) {
12
+ require(is_string(value), "gh: " + label + " must be a string");
13
+ require(index_of(value, from_char_code(0)) < 0, "gh: " + label + " must be NUL-free");
14
+ return value;
15
+ }
16
+ fn _variable(name, value) {
17
+ _text(name, "variable name");
18
+ require(regex_test(name, "^[_A-Za-z][_0-9A-Za-z]*$") && name != "query" && name != "operationName",
19
+ "gh: invalid or reserved variable name");
20
+ flag = "-f";
21
+ encoded = "";
22
+ if (is_string(value)) {
23
+ encoded = _text(value, "variable " + name);
24
+ } else if (value == null || type(value) == "boolean") {
25
+ flag = "-F";
26
+ encoded = json_stringify(value);
27
+ } else {
28
+ require(is_number(value) && value >= -9007199254740991 && value <= 9007199254740991 && floor(value) == value,
29
+ "gh: variable " + name + " must be a string, boolean, null or safe integer; floats and compound values are not supported");
30
+ flag = "-F";
31
+ encoded = str(value);
32
+ }
33
+ return [flag, name + "=" + encoded];
34
+ }
35
+ fn _checked(result) {
36
+ text = result.stderr;
37
+ if (ends_with(text, "\n")) { text = slice(text, 0, len(text)-1); }
38
+ tail = join(slice(split(text, "\n"), -20), "\n");
39
+ require(result.code == 0 && result.signal == null && !result.timed_out,
40
+ "gh api graphql failed (exit " + str(result.code) + ", signal " + str(result.signal) + "): " + tail);
41
+ response = json_parse(result.stdout);
42
+ require(is_map(response) && (has_key(response, "data") || has_key(response, "errors")),
43
+ "gh api graphql: expected a response map with data or errors");
44
+ if (has_key(response, "errors") && response.errors != null) {
45
+ require(is_array(response.errors), "gh api graphql: errors must be an array");
46
+ messages = [];
47
+ for (problem in response.errors) {
48
+ require(is_map(problem) && is_string(problem.message), "gh api graphql: error entry must contain a message");
49
+ push(messages, problem.message);
50
+ }
51
+ require(len(messages) == 0, "gh api graphql: " + join(messages, "; "));
52
+ }
53
+ return response;
54
+ }
55
+ fn gh_graphql(query, vars) {
56
+ _text(query, "query");
57
+ require(is_map(vars), "gh: variables must be a map");
58
+ flags = [];
59
+ for (name in keys(vars)) { flags = concat(flags, _variable(name, vars[name])); }
60
+ result = null;
61
+ if (len(flags) == 0) {
62
+ result = system gh api graphql -f query=${query};
63
+ } else {
64
+ argv = cmd gh api graphql -f query=${query};
65
+ result = system(concat(argv, flags));
66
+ }
67
+ return _checked(result);
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmctl-ai/lmctl",
3
- "version": "0.2.110",
3
+ "version": "0.2.112",
4
4
  "description": "A provider-agnostic control plane for teams of AI coding agents — across providers, with independent review and durable memory.",
5
5
  "type": "module",
6
6
  "homepage": "https://lmctl.com",
@@ -34,7 +34,8 @@
34
34
  "README.md",
35
35
  "CHANGELOG.md",
36
36
  "examples/",
37
- "modules/git.lms"
37
+ "modules/git.lms",
38
+ "modules/gh.lms"
38
39
  ],
39
40
  "engines": {
40
41
  "node": ">=24.15.0"