项目作者: CognitiveScale

项目描述 :
CognitiveScale Cortex CLI Tool
高级语言: JavaScript
项目地址: git://github.com/CognitiveScale/cortex-cli.git
创建时间: 2018-02-08T16:33:33Z
项目社区:https://github.com/CognitiveScale/cortex-cli

开源协议:Apache License 2.0

下载


Cortex CLI

A command line utility for the Cortex Platform.

Build Status

Installation:

From NPM:

  1. npm install -g cortex-cli

From Source:

Once you have the code pulled, run this command from the cortex-cli directory:

  1. npm install -g .

NOTE: When we have a release of this module, it will be published to npm.org for distribution.

For Developers:

You can link your local copy of cortex-cli to your globally installed version:

  1. npm link

The cortex cli can be run directly from the source with a simple wrapper script

  1. git clone https://github.com/CognitiveScale/cortex-cli.git
  2. cat > /usr/local/bin/cortex <<EOM
  3. #!/bin/bash
  4. $PWD/cortex-cli/bin/cortex.js "\$@"
  5. EOM
  6. chmod +x /usr/local/bin/cortex

Changes you make to the source code will now be available immediately (locally).

Usage:

  1. cortex <command> [sub-command] [options]

Common Options

  • -h, —help
  • -v, —version

Getting Started

  1. cortex configure --file /personal/access/token.json --project defaultProject
  2. or
  3. cortex configure --project defaultProject
  4. Cortex Personal Access Token: <paste access token>

Upon successful login, a config file will be saved in your home directory with your authentication token for future use. (NOTE: currently, you will have to re-run the configure command when your token expires).

To see a list of agents:

  1. cortex agents list
  2. [
  3. {
  4. "title": "Movie Recommendation Agent",
  5. "description": "Makes personalized movie recommendations for users.",
  6. "createdAt": "2017-12-22T03:07:39.863Z",
  7. "updatedAt": "2017-12-22T03:12:32.159Z",
  8. "name": "tutorial/movie_recommendation"
  9. },
  10. {
  11. "title": "Trading Insights Agent",
  12. "description": "Agent to generate personalized insights for traders.",
  13. "createdAt": "2017-12-22T03:07:40.109Z",
  14. "updatedAt": "2017-12-22T03:07:40.201Z",
  15. "name": "default/trading-insights-agent"
  16. },
  17. {
  18. "title": "Client Complaints Agent",
  19. "description": "Agent to intercept and classify customer complaints early in the process before it even goes to internal audit.",
  20. "createdAt": "2017-12-22T03:07:41.287Z",
  21. "updatedAt": "2017-12-22T03:07:41.360Z",
  22. "name": "default/client-complaints-agent"
  23. }
  24. ]

To use a different profile:

  1. cortex configure --profile myprofile
  2. ...
  3. cortex agents list --profile myprofile

Filtering Results using the —json or —query option (DEPRECATION WARNING for —query)

Many of the commands support a —json / —query option for filtering JSON responses. Queries use JMESPath to filter JSON documents. The specification for JMESPath can be found here: http://jmespath.org/. It is similar to the popular JQ tool and supported by Amazon AWS and some other notable services.

For example, if I want to select just the name and title from my previous output:

  1. cortex agents list --json "[].{name: name, title: title}"
  2. [
  3. {
  4. "name": "tutorial/movie_recommendation",
  5. "title": "Movie Recommendation Agent"
  6. },
  7. {
  8. "name": "default/trading-insights-agent",
  9. "title": "Trading Insights Agent"
  10. },
  11. {
  12. "name": "default/client-complaints-agent",
  13. "title": "Client Complaints Agent"
  14. }
  15. ]

Standalone binary

We use caxa https://github.com/leafac/caxa to build standalone binaries.
Previously, we used pkg but it doesn’t support ESM without transpilation as of 07/2023

Executables are created for the following platforms:

  • Linux 64bit intel
  • Windows 64bit intel
  • macOS 64 bit intel.
  • macOS 64 bit M1/M2.

Signed binaries status

  • windows: binaries are currently unsigned
  • macOS: adhoc signature using ldid

Subcommands & Compatibility Checks

The following sequene diagram shows an example running a command with Cortex CLI - namely which HTTP requests. (This diagram can be viewered here).

The Cortex CLI will limit the set of available subcommands, to those which are supported by the Cortex cluster that it is
communicating with.

  1. sequenceDiagram
  2. autonumber
  3. Actor Dev
  4. box CLI Commands
  5. participant C as cortex
  6. participant Sub as cortex pipelines
  7. end
  8. participant Filesystem
  9. participant S as Sensa API
  10. participant N as NPM
  11. Dev->>+C: cortex pipelines list
  12. critical Load Profile
  13. C->>+Filesystem: READ $HOME/.cortex/config
  14. Filesystem->>+C: Cluster URL, Project, etc.
  15. C->>+S: HTTP GET /fabric/v4/info
  16. S->>+C: JSON (Server Time Stamp, Feature Flags)
  17. C-->+C: Limit Subcommands based on feature flags
  18. end
  19. alt Is Subcommand Supported?
  20. C->>Sub: delegate to subcommand
  21. else
  22. C->>+Dev: Error: Unknown Command
  23. end
  24. Note over Sub,N: Run Compatibility Check
  25. critical Compatibility Check
  26. Sub->>S: HTTP GET /fabric/v4/compatibility/applications/cortex-cli
  27. S->>+Sub: JSON (Required Version)
  28. Sub->>+N: HTTP GET <npm-registry-url>
  29. N->>+Sub: JSON (Available CLI Versions)
  30. end
  31. Note over Sub,S: Run Action
  32. critical List Pipelines
  33. Sub->>S: HTTP GET /fabric/v4/projects/<project>/pipeline-repositories
  34. S->>+Sub: JSON (Pipelines)
  35. end

Practical Notes:

  • Only want to load the Profile & perform a Compatibility Check once during command execution
  • Clear downside is that startup for initial help commands are slightly slower due to the dynamic nature of loading
    subcommands

Preview Features

All preview features cam be enabled in the CLI by setting the PREVIEW_FEATURES_ENABLED environment variable.

  1. Example
  2. ```
  3. PREVIEW_FEATURES_ENABLED=* cortex -h
  4. ```