Skip to content

Latest commit

 

History

History
105 lines (69 loc) · 3.37 KB

quickstart.md

File metadata and controls

105 lines (69 loc) · 3.37 KB

Quickstart

Codemode runs JavaScript that calls actions. Actions come from plugins, and a plugin becomes available once it has a connection. This page installs codemode, adds two connections, and runs code against them.

1. Install codemode

Install the command-line interface from npm. This requires Node.js 22.12 or newer, or 20.19 or newer on the Node.js 20 line:

npm install -g @shiftlabs/codemode

Verify the installation:

codemode --version

2. Create a project

Change to the folder you want to work in, then create its .codemode folder:

cd /path/to/folder
codemode init

codemode init creates .codemode/config.json and an empty .codemode/plugins/ folder. Codemode reads the nearest .codemode folder at or above the working directory.

3. Add a connection

A plugin is a set of actions for one service. A connection is the configuration a plugin runs with, usually its credentials.

The bundled hackernews plugin needs no credentials. Add a connection to make it available:

codemode connection add hackernews --plugin hackernews

Most plugins need a key or token. Pass it with --set:

codemode connection add gh --plugin github --set token=$GITHUB_TOKEN

See Bundled Plugins for every plugin and the values it needs, and Connections for environment variables and OAuth logins.

4. Run code

Pass JavaScript to codemode exec. Each plugin with a connection is a global, and return produces the result:

codemode exec 'return await hackernews.all.top({ limit: 3 })'

One run can call several actions and combine their results:

codemode exec '
  const repo = await github.repository.get({ owner: "nodejs", repo: "node" });
  const [story] = await hackernews.all.top({ limit: 1 });
  return { stars: repo.stargazers_count, top: story.title };
'

Actions that create, change, or send something run without asking. Review code before running it against a real account. See Security.

5. Discover actions

Code can search and inspect the available actions through the actions object:

codemode exec 'return actions.find("create issue")'
codemode exec 'return actions.describe("github.issue.create")'

See Run Code for the complete discovery flow, logs, and JSON output.

Next steps

  • Run code to learn the calling conventions and what the runtime provides.
  • Write a plugin to add actions for an API that is not bundled.
  • Use the SDK to run the same code from an application.

Choose how to extend codemode

Start with the least powerful mechanism that meets your need:

Need Start with
Call a service that codemode already supports A connection for the bundled plugin
Add actions for one project A plugin file in .codemode/plugins/
Add actions for every project on your machine A plugin file in ~/.codemode/plugins/
Share plugins with other people or projects A package
Run code and manage connections from an application The SDK

Uninstall codemode

Remove the command-line interface with npm:

npm uninstall -g @shiftlabs/codemode

This does not remove ~/.codemode, which holds your plugins, installed packages, and trust decisions, or any project's .codemode folder.