{"id":13500647,"url":"https://github.com/hliyan/jarvis","last_synced_at":"2025-04-09T17:41:53.169Z","repository":{"id":46945520,"uuid":"137552103","full_name":"hliyan/jarvis","owner":"hliyan","description":"J.A.R.V.I.S - Just Another Rudimentary Verbal Instruction Shell","archived":false,"fork":false,"pushed_at":"2023-01-03T15:16:11.000Z","size":361,"stargazers_count":126,"open_issues_count":11,"forks_count":14,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T19:44:39.673Z","etag":null,"topics":["chatbot","cli","nlp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hliyan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-16T04:15:41.000Z","updated_at":"2025-01-11T12:40:20.000Z","dependencies_parsed_at":"2023-02-01T07:01:07.115Z","dependency_job_id":null,"html_url":"https://github.com/hliyan/jarvis","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hliyan%2Fjarvis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hliyan%2Fjarvis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hliyan%2Fjarvis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hliyan%2Fjarvis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hliyan","download_url":"https://codeload.github.com/hliyan/jarvis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248079404,"owners_count":21044308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","cli","nlp"],"created_at":"2024-07-31T22:01:08.365Z","updated_at":"2025-04-09T17:41:53.131Z","avatar_url":"https://github.com/hliyan.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# J.A.R.V.I.S - Just Another Rudimentary Verbal Instruction Shell (BETA)\n\n![build](https://travis-ci.org/hliyan/jarvis.svg?branch=master) \n[![Coverage Status](https://coveralls.io/repos/github/hliyan/jarvis/badge.svg?branch=master)](https://coveralls.io/github/hliyan/jarvis?branch=master)\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Basic example: wrapping an existing library](#basic-example-wrapping-an-existing-library)\n- [Command line integration](#command-line-integration)\n- [Interactive CLI](#interactive-cli)\n- [Script mode](#script-mode)\n- [Constants](#constants)\n- [Macros and variables](#macros-and-variables\n\n## Introduction\n\nJARVIS helps you write rudimentary English wrappers around libraries or APIs, like this:\n\n```javascript\n// wrap your JavaScript function with an English API:\njarvis.addCommand({\n  command: '$number to the power of $power',\n  handler: ({args: {number, power}}) =\u003e {\n    const result = Math.pow(parseInt(number), parseInt(power));\n    return `${number} to the power of ${power} is ${result}!`;\n  }\n});\n```\n\nUse it from an interactive command line prompt\n\n```shell\n\u003e 2 to the power of 3\n  2 to the power of 3 is 8!\n```\n\n## Installation\n\n```\nnpm install --save hliyan/jarvis\n```\n\n## Basic example: wrapping an existing library\n\nInvoke an API using natural language.\n\n```javascript\n\nconst Jarvis = require('jarvis');            // use jarvis to\nconst IssueClient = require('issue-client'); // wrap this with a basic english API\n\nconst app = new Jarvis();\nconst client = new IssueClient();\n\n// register command\napp.addCommand({\n  command: 'connectToRepository $repoName',\n  aliases: [\n    'connect to $repoName',\n    'connect repo $repoName',\n    'connect to $repoName repo'\n  ],\n  handler: async ({args: {repoName}}) =\u003e {\n    const res = await client.connect(repoName);\n    return res.success ? `Connected to ${repoName}.` : `Could not connect to ${repoName}. Here's the error: ${res.error}`;\n  }\n});\n\n// exercise the command\nconst res = await app.send('connect to hliyan/jarvis');\nconsole.log(res); // \"Connected to hliyan/jarvis.\"\n```\n\n## Command line integration\n\nInvoke an API using natural language, as a shell command.\n\n```javascript\nconst FAQClient = require('./faq');   // business logic from here\nconst Jarvis = require('jarvis');     // wrapped by jarvis \nconst readline = require('readline'); // and connected to a command line\n\nconst app = new Jarvis();\nconst client = new FAQClient();\n\n// register the command\napp.addCommand({\n  command: 'getCountryPresident $country',\n  aliases: [\n    'who is the president of $country',\n    '$country president'\n  ],\n  handler: async ({args: {country}}) =\u003e {\n    const president = await client.getPresident(country);\n    return president ? `the president of ${country} is ${president}`\n      : `i don't know ${country}`;\n  }\n});\n\n// start the CLI\nconst rl = readline.createInterface({\n  input: process.stdin,\n  output: process.stdout,\n  prompt: 'jarvis\u003e '\n});\n\nrl.prompt();\n\n// feed CLI input to the app, and app output back to CLI\nrl.on('line', async (line) =\u003e {\n  const res = await app.send(line.trim());\n  console.log(res ? `  ${res}` : '  I don\\'t understand');\n  rl.prompt();\n});\n\n// TODO: error handling and other best practices\n```\n\nRunning:\n```shell\n$ node index.js\njarvis\u003e who is the president of russia\n  the president of russia is Vladamir Putin\njarvis\u003e usa president\n  the president of usa is Barack Obama\njarvis\u003e us president\n  i don't know us\njarvis\u003e foo\n  I don't understand\njarvis\u003e \n```\n\n* Full source: [hliyan/jarvis-sample-app](https://github.com/hliyan/jarvis-sample-app)\n\n## Interactive CLI\n\nUse this when the workflow you're trying to wrap is too complicated to execute as a single line command.\n\nYou can enter an interactive command session using `jarvis.startCommand($name)` and exit that particular session using `jarvis.endCommand()`. State that needs to be maintained for the duration of the interactive session can be set using `jarvis.setCommandState($object)`.\n\n```javascript\n  const jarvis = new Jarvis();\n  jarvis.addCommand({\n    command: 'repl',\n    handler: ({context, line}) =\u003e {\n      if (!context.activeCommand) {\n        context.startCommand('repl');\n        context.setCommandState({status: 'awaitInput'});\n        return 'Enter input: ';\n      }\n  \n      if (context.state.status === 'awaitInput') {\n        const out = 'Handled: ' + line;\n        return out;\n      }\n    }\n  });\n```\n\nExpected output\n```\n$ repl\n$ Enter input:\n$ bar\n$ Handled: bar\n$ ..  # built in exit\n$ Done with repl.\n```\n\n## Script mode\n\nYou can use this to run your natural language commands as a script.\n\nCreate a script file, e.g.\n\n```\nstart\n  connect to repo 'hliyan/jarvis'\n  get open issues\n  write issues to 'home/john/issues.json'\nend\n```\n\nCreate a script runner with the correct bindings\n\n```\nconst Jarvis = require('jarvis');\nconst app = new Jarvis();\n\n// bind commands as described earlier\n\n// run script\napp.run('test.jarvis', function(input, output) {\n  console.log(input);\n  console.log(output);\n});\n\n```\n\n## Constants\n\n```\nin this context\n  HOME is 'https://foo.bar.com'\n  USER is 'john'\nend\n```\n\n## Macros and variables\n\nYou can use this to re-use blocks of commands within a script.\n\n```\nin this context\n  PI is 3.14\nend\n\nhow to get area of circle with radius $radius\n  # more statements here\nend\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhliyan%2Fjarvis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhliyan%2Fjarvis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhliyan%2Fjarvis/lists"}