codeapp-js-cli
v0.1.5
Published
CAP CLI and Node.js API for Power Apps code apps
Maintainers
Readme
CodeApp JS CLI
codeapp-js-cli supports two non-breaking use cases:
- Install it globally and use
capas a terminal command. - Install it as a project dependency and either call the local CLI or import the Node.js API.
cap is a thin wrapper around the local @microsoft/power-apps-cli package and does not require an external pac installation.
Install And Use As A Standalone CLI
Install globally:
npm install -g codeapp-js-cliThen run the CLI from any terminal:
cap
cap-p <prompt>
cap auth
cap environment --info
cap setupNotes:
capis the portable command name to document and script against.- The package also exposes
CAPas an alias for shells where you want the uppercase form. - Global install is the right choice when you want one CLI available across multiple workspaces on the same machine.
Install And Use As A Dependency
Install into a project:
npm install codeapp-js-cliUse the local CLI from that project directory without a global install:
npx cap --help
npx cap authRun the CLI from any directory without installing it globally:
npx --package codeapp-js-cli cap --help
npx --package codeapp-js-cli cap authOr wire it into package scripts:
{
"scripts": {
"cap": "cap",
"cap:setup": "cap setup",
"cap:deploy": "cap deploy"
}
}Node.js API
The package root continues to export the reusable command functions from lib/cap-core.js, so existing dependency consumers are not forced to change imports.
CommonJS:
const {
capChat,
capEnvironment,
capSetup,
parseCommandInput,
} = require('codeapp-js-cli');
async function run() {
const parsed = parseCommandInput(process.argv.slice(2));
if (parsed.target === 'setup') {
await capSetup();
return;
}
await capEnvironment(undefined, { namedArgs: { info: true } });
await capChat();
}
run().catch((error) => {
console.error(error.stderr || error.stdout || error.message);
process.exit(typeof error.code === 'number' ? error.code : 1);
});ES modules:
import cap from 'codeapp-js-cli';
await cap.capSetup();Compatibility notes:
require('codeapp-js-cli')still resolves to the samelib/cap-core.jsAPI surface.- Deep imports such as
require('codeapp-js-cli/lib/cap-core')andrequire('codeapp-js-cli/lib/cap-core.js')remain available for older integrations. - The CLI entry point remains
bin/cap.js, exposed through thecapandCAPexecutables.
npx Troubleshooting
If npx cap fails with a path under %APPDATA%\npm\node_modules\codeapp-js-cli\bin\cap.js, npx is running a stale global shim instead of a project-local install.
Use one of these fixes:
# From any directory, bypass the global shim entirely
npx --package codeapp-js-cli cap --help# Repair the broken global install on Windows
npm uninstall -g codeapp-js-cli
Remove-Item "$env:APPDATA\npm\cap.cmd","$env:APPDATA\npm\cap.ps1","$env:APPDATA\npm\CAP.cmd","$env:APPDATA\npm\CAP.ps1" -Force -ErrorAction SilentlyContinue
npm install -g codeapp-js-cliCommands
cap
cap auth
cap auth --change
cap auth --logout
cap copilot
cap copilot --token <githubToken>
cap copilot --logout
cap model
cap model --<publisher/model>
cap skills
cap skills --<skill>
cap instruction
cap instruction --edit
cap instruction --delete
cap instruction --<markdownPath>
cap session
cap session --<session>
cap edit
cap edit --<filePath>
cap mockup
cap mockup --<number>
cap environment
cap environment --<environmentURL>
cap environment --info
cap dataverse --<table-logical-name>
cap flow
cap flow --<flow-id>
cap connection --<apiName>
cap setup
cap deploy
cap deploy --debuggerBehavior
capstarts the interactive Copilot chat session, loads the active session fromagent/, reads prompt and instruction files from the CLI setup directory, and runs the conversation through the official GitHub Copilot CLI SDK while saving local session metadata back intoagent/*.session.json. Inside chat, slash commands now run either CAP commands such as/modelor shell commands such as/git statusand/cd ...cap-p <prompt>runs a one-off Copilot turn using the current CAP prompt and instruction files, but does not create or reuse any saved CAP session.cap authstarts an interactive browser login using the bundled MSAL auth provider and caches credentials locally for later CAP commands.cap auth --changeclears the local auth cache and forces an account-picker login.cap auth --logoutclears the cached login.cap copilotlaunches the official GitHub Copilot CLI login flow when you press Enter in an interactive shell, or saves a token accepted by Copilot CLI when you paste one.cap copilot --logoutclears the CAP-saved Copilot metadata and, on Windows, also removes bundled Copilot OAuth credentials stored bycopilot login.cap modelreads the live GitHub Copilot model list through@github/copilot-sdkand stores the selected model in the CLI setup workspace config.cap model --debugprints the live GitHub Copilot model source, auth identity, and available model ids seen by the current Copilot account.cap model --<model>updates the CLI-selected model without opening the picker.cap skillsopens a bundled skill file from the installedcodeapp-js/AI/skills/folder;cap skills --<skill>quick-opens a matching packaged skill.cap instructionprints the CLI instruction file.cap instruction --editopens the CLI instruction file in VS Code or the platform fallback editor.cap instruction --deleteremoves the CLI instruction file.cap instruction --docs/rules.mdcopies that Markdown file into the CLI instruction file.cap sessionlists saved chats fromagent/and marks the selected one as the active context for the nextcapchat session.cap editlists workspace files and opens the selected file in VS Code or the platform fallback editor.cap mockuplists HTML files underagent/, then opens the selected mockup in the default browser.cap mockup --1opens the first listed mockup directly.cap environmentlists tenant environments, lets you filter/select one, and writes the selected environment ID topower.config.json.cap environment --<environmentURL>selects the environment whose Dynamics URL matches the provided URL.cap environment --infoprints the current environment display name, Dynamics URL, and environment ID.cap dataverse --accountadds the Dataverse table data source through the bundled action layer.cap flowrunspower-apps list-flows --json, lets you filter/select, then runspower-apps add-flow --flow-id <id>.cap flow --<flow-id>directly runspower-apps add-flow --flow-id <id>.cap connection --<apiName>lists connections for that connector through the bundled service layer, selects the first one, then adds it as a data source.cap setupcopies the bundledcodeapp-js/codeApptemplate contents into the current working directory, then prompts for the app display name and description and writes them intopower.config.json.cap deployrunspower-apps push, extracts the app ID from the returned play URL, and writes it topower.config.jsonasappId.cap deploy --debuggerprepends the debugger bootstrap todist/index.jsbefore pushing.
Copilot Backend
- CAP now uses the official GitHub Copilot CLI SDK instead of the
models.github.aiREST catalog and inference endpoints. - Available models come from the active Copilot account, so the picker now follows the Copilot model surface rather than the GitHub Models PAT catalog.
- Tool execution and file changes are handled by the Copilot CLI runtime, with CAP prompting for per-action approval.
Copilot Auth Notes
- Saved Copilot sign-in is stored in the local CAP user config.
- Runtime auth prefers a Copilot CLI logged-in user, then
COPILOT_GITHUB_TOKEN/GH_TOKEN/GITHUB_TOKEN, then the saved CAP token. CAP copilot --logoutnow removes CAP-saved metadata and also clears bundled Copilot OAuth state on Windows by deleting the.copilotremembered-user entries plus the matchingcopilot-cli/...Windows Credential Manager target.- For environment variables, GitHub CLI auth, or explicit tokens, remove or change that source directly.
- Running
CAP copilotin an interactive shell launches Copilot device login when you press Enter at the token prompt. - If you prefer a non-interactive setup, set
COPILOT_GITHUB_TOKEN,GH_TOKEN, orGITHUB_TOKEN.
Reuse Model
The command logic lives in lib/cap-core.js and is exported from the package root so other tools can build on top of the same command implementations without reimplementing shell behavior.
Lean Update Flow
- Update the wrapped CLI with
npm run update:power-apps-cli. - Remove non-production packages with
npm run prune:production. - Package output stays lean because
package.jsonwhitelists onlybin,lib, andREADME.md, while bundled assets come from thecodeapp-jsdependency.
Requirements
- Node.js 20+
