@opscompass/skills 0.2.0 → 0.2.1

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/manifest.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "schemaVersion": 1,
3
3
  "scope": "public",
4
4
  "name": "@opscompass/skills",
5
- "version": "0.2.0",
5
+ "version": "0.2.1",
6
6
  "source": {
7
7
  "repository": "https://gitlab.com/opscompass-hob/opscompass-ai/opscompassai.git",
8
- "revision": "e96ebc310fdaff22d6b9861025380528e59bcae8",
8
+ "revision": "e71529c9bf8952fa65fc291216a07c54e15e29ad",
9
9
  "dirty": false
10
10
  },
11
11
  "skills": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opscompass/skills",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Public OpsCompass Skills with portable compiled tools and runtime assets",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -22,3 +22,13 @@ export function resolveCliContext(cliCommand) {
22
22
  opscompassHome: path.join(os.homedir(), `.${selectedCommand}`),
23
23
  };
24
24
  }
25
+ export function resolveCliInvocation(context, args) {
26
+ return {
27
+ executable: context.cliInvocation?.executable ?? context.cliEntryPoint,
28
+ args: [...(context.cliInvocation?.args ?? []), ...args],
29
+ env: {
30
+ ...(context.cliInvocation?.env ?? process.env),
31
+ OPSCOMPASS_CLI_ENTRYPOINT: context.cliEntryPoint,
32
+ },
33
+ };
34
+ }
@@ -1,31 +1,41 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { resolveCliInvocation } from "./opsc-cli-context.js";
2
3
  const MAX_TIMEOUT_SECONDS = 120;
3
4
  const MAX_OUTPUT_BYTES = 100_000;
4
5
  export async function runCli(context, args) {
5
- const child = spawn(context.cliEntryPoint, args, {
6
+ if (context.signal.aborted)
7
+ throw new Error("Opscompass command aborted.");
8
+ const invocation = resolveCliInvocation(context, args);
9
+ const child = spawn(invocation.executable, invocation.args, {
10
+ shell: false,
6
11
  cwd: context.workspaceRoot,
7
12
  // The host-selected executable must win over ambient standalone overrides.
8
13
  env: {
9
- ...process.env,
10
- OPSCOMPASS_CLI_ENTRYPOINT: context.cliEntryPoint,
14
+ ...invocation.env,
11
15
  ELECTRON_RUN_AS_NODE: "1",
12
16
  OPSCOMPASS_STUDIO: "1",
13
17
  },
14
18
  stdio: ["ignore", "pipe", "pipe"],
15
19
  detached: process.platform !== "win32",
16
20
  });
17
- const chunks = [];
18
- let outputBytes = 0;
21
+ const stdout = [];
22
+ const stderr = [];
23
+ let stdoutBytes = 0;
24
+ let stderrBytes = 0;
19
25
  let timedOut = false;
20
- const collect = (chunk) => {
26
+ const collect = (chunks, chunk, outputBytes) => {
21
27
  if (outputBytes >= MAX_OUTPUT_BYTES)
22
- return;
28
+ return outputBytes;
23
29
  const bounded = chunk.subarray(0, MAX_OUTPUT_BYTES - outputBytes);
24
30
  chunks.push(bounded);
25
- outputBytes += bounded.length;
31
+ return outputBytes + bounded.length;
26
32
  };
27
- child.stdout?.on("data", collect);
28
- child.stderr?.on("data", collect);
33
+ child.stdout?.on("data", (chunk) => {
34
+ stdoutBytes = collect(stdout, chunk, stdoutBytes);
35
+ });
36
+ child.stderr?.on("data", (chunk) => {
37
+ stderrBytes = collect(stderr, chunk, stderrBytes);
38
+ });
29
39
  let graceTimer;
30
40
  const forceKill = () => {
31
41
  try {
@@ -59,13 +69,15 @@ export async function runCli(context, args) {
59
69
  const result = new Promise((resolve, reject) => {
60
70
  child.once("error", reject);
61
71
  child.once("close", (code) => {
62
- const output = Buffer.concat(chunks).toString("utf8");
72
+ const output = Buffer.concat(stdout).toString("utf8");
73
+ const diagnostic = Buffer.concat(stderr).toString("utf8");
63
74
  if (context.signal.aborted)
64
75
  reject(new Error("Opscompass command aborted."));
65
76
  else if (timedOut)
66
77
  reject(new Error(`Opscompass command timed out after ${MAX_TIMEOUT_SECONDS} seconds.`));
67
78
  else if (code !== 0)
68
- reject(new Error(output.trim() ||
79
+ reject(new Error(diagnostic.trim() ||
80
+ output.trim() ||
69
81
  `Opscompass command failed with exit code ${code}.`));
70
82
  else
71
83
  resolve(output);
@@ -1,2 +1,3 @@
1
1
  import { oracleAssessmentTool } from "./oracle-assessment.tool.js";
2
+ export const supportsCliInvocation = true;
2
3
  export const tools = [oracleAssessmentTool];
@@ -22,3 +22,13 @@ export function resolveCliContext(cliCommand) {
22
22
  opscompassHome: path.join(os.homedir(), `.${selectedCommand}`),
23
23
  };
24
24
  }
25
+ export function resolveCliInvocation(context, args) {
26
+ return {
27
+ executable: context.cliInvocation?.executable ?? context.cliEntryPoint,
28
+ args: [...(context.cliInvocation?.args ?? []), ...args],
29
+ env: {
30
+ ...(context.cliInvocation?.env ?? process.env),
31
+ OPSCOMPASS_CLI_ENTRYPOINT: context.cliEntryPoint,
32
+ },
33
+ };
34
+ }
@@ -1,31 +1,41 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { resolveCliInvocation } from "./opsc-cli-context.js";
2
3
  const MAX_TIMEOUT_SECONDS = 120;
3
4
  const MAX_OUTPUT_BYTES = 100_000;
4
5
  export async function runCli(context, args) {
5
- const child = spawn(context.cliEntryPoint, args, {
6
+ if (context.signal.aborted)
7
+ throw new Error("Opscompass command aborted.");
8
+ const invocation = resolveCliInvocation(context, args);
9
+ const child = spawn(invocation.executable, invocation.args, {
10
+ shell: false,
6
11
  cwd: context.workspaceRoot,
7
12
  // The host-selected executable must win over ambient standalone overrides.
8
13
  env: {
9
- ...process.env,
10
- OPSCOMPASS_CLI_ENTRYPOINT: context.cliEntryPoint,
14
+ ...invocation.env,
11
15
  ELECTRON_RUN_AS_NODE: "1",
12
16
  OPSCOMPASS_STUDIO: "1",
13
17
  },
14
18
  stdio: ["ignore", "pipe", "pipe"],
15
19
  detached: process.platform !== "win32",
16
20
  });
17
- const chunks = [];
18
- let outputBytes = 0;
21
+ const stdout = [];
22
+ const stderr = [];
23
+ let stdoutBytes = 0;
24
+ let stderrBytes = 0;
19
25
  let timedOut = false;
20
- const collect = (chunk) => {
26
+ const collect = (chunks, chunk, outputBytes) => {
21
27
  if (outputBytes >= MAX_OUTPUT_BYTES)
22
- return;
28
+ return outputBytes;
23
29
  const bounded = chunk.subarray(0, MAX_OUTPUT_BYTES - outputBytes);
24
30
  chunks.push(bounded);
25
- outputBytes += bounded.length;
31
+ return outputBytes + bounded.length;
26
32
  };
27
- child.stdout?.on("data", collect);
28
- child.stderr?.on("data", collect);
33
+ child.stdout?.on("data", (chunk) => {
34
+ stdoutBytes = collect(stdout, chunk, stdoutBytes);
35
+ });
36
+ child.stderr?.on("data", (chunk) => {
37
+ stderrBytes = collect(stderr, chunk, stderrBytes);
38
+ });
29
39
  let graceTimer;
30
40
  const forceKill = () => {
31
41
  try {
@@ -59,13 +69,15 @@ export async function runCli(context, args) {
59
69
  const result = new Promise((resolve, reject) => {
60
70
  child.once("error", reject);
61
71
  child.once("close", (code) => {
62
- const output = Buffer.concat(chunks).toString("utf8");
72
+ const output = Buffer.concat(stdout).toString("utf8");
73
+ const diagnostic = Buffer.concat(stderr).toString("utf8");
63
74
  if (context.signal.aborted)
64
75
  reject(new Error("Opscompass command aborted."));
65
76
  else if (timedOut)
66
77
  reject(new Error(`Opscompass command timed out after ${MAX_TIMEOUT_SECONDS} seconds.`));
67
78
  else if (code !== 0)
68
- reject(new Error(output.trim() ||
79
+ reject(new Error(diagnostic.trim() ||
80
+ output.trim() ||
69
81
  `Opscompass command failed with exit code ${code}.`));
70
82
  else
71
83
  resolve(output);
@@ -1,6 +1,6 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { isMainModule } from "../.opscompass-runtime/tools/cli-entrypoint.js";
3
- import { resolveCliContext } from "../.opscompass-runtime/tools/opsc-cli-context.js";
3
+ import { resolveCliContext, resolveCliInvocation, } from "../.opscompass-runtime/tools/opsc-cli-context.js";
4
4
  import { resolveCompany } from "../.opscompass-runtime/tools/opsc-cli-defaults.js";
5
5
  export { resolveCompany };
6
6
  export const ALLOWED_LIST_PARAMS = new Set([
@@ -81,7 +81,9 @@ const shellQuote = (value) => /^[A-Za-z0-9_./:-]+$/.test(value)
81
81
  export const commandText = (command) => command.map(shellQuote).join(" ");
82
82
  function runCommand(command, context) {
83
83
  return new Promise((resolve, reject) => {
84
- const child = spawn(context.cliEntryPoint, command.slice(1), {
84
+ const invocation = resolveCliInvocation(context, command.slice(1));
85
+ const child = spawn(invocation.executable, invocation.args, {
86
+ env: invocation.env,
85
87
  shell: false,
86
88
  stdio: "inherit",
87
89
  });
@@ -2,7 +2,7 @@ import { mkdirSync, writeFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { spawn } from "node:child_process";
4
4
  import { isMainModule } from "../.opscompass-runtime/tools/cli-entrypoint.js";
5
- import { resolveCliContext } from "../.opscompass-runtime/tools/opsc-cli-context.js";
5
+ import { resolveCliContext, resolveCliInvocation, } from "../.opscompass-runtime/tools/opsc-cli-context.js";
6
6
  import * as brc from "./build_resources_command.js";
7
7
  import * as moc from "./map_oracle_workloads_to_platform_cpus.js";
8
8
  import * as slc from "./summarize_latest_configuration.js";
@@ -23,7 +23,8 @@ function runJsonCommand(command, verbose, logger, execution) {
23
23
  if (verbose)
24
24
  logger.error(`$ ${command.join(" ")}`);
25
25
  let stdout = "", stderr = "";
26
- const child = spawn(execution.context.cliEntryPoint, command.slice(1), {
26
+ const invocation = resolveCliInvocation(execution.context, command.slice(1));
27
+ const child = spawn(invocation.executable, invocation.args, {
27
28
  shell: false,
28
29
  stdio: ["ignore", "pipe", "pipe"],
29
30
  cwd: execution.workspaceRoot,
@@ -503,8 +504,7 @@ async function runWorkflow(argv, logger, execution, signal) {
503
504
  : process.cwd(),
504
505
  signal,
505
506
  env: {
506
- ...process.env,
507
- OPSCOMPASS_CLI_ENTRYPOINT: context.cliEntryPoint,
507
+ ...resolveCliInvocation(context, []).env,
508
508
  ...(execution
509
509
  ? { ELECTRON_RUN_AS_NODE: "1", OPSCOMPASS_STUDIO: "1" }
510
510
  : {}),
@@ -5,6 +5,7 @@ import { opscompassDefaultsTool } from "./opscompass-defaults.tool.js";
5
5
  import { opscompassResourcesTool } from "./opscompass-resources.tool.js";
6
6
  import { summarizeLatestConfigurationTool } from "./summarize-latest-configuration.tool.js";
7
7
  import { summarizeResourcesListTool } from "./summarize-resources-list.tool.js";
8
+ export const supportsCliInvocation = true;
8
9
  export const tools = [
9
10
  opscompassResourcesTool,
10
11
  buildResourcesCommandTool,