reworkings to support npm.org-based installation (#11)

* reworked things a bit to support npm-based installation
diff --git a/README.md b/README.md
index b39e2fc..6a18821 100644
--- a/README.md
+++ b/README.md
@@ -1,144 +1,3 @@
 # wskdb: The OpenWhisk Debugger
 
-This project currently supports debugging [OpenWhisk](https://console.ng.bluemix.net/openwhisk) actions written in NodeJS, Python, and Swift. The debugger will arrange things so that the actions you wish to debug will be offloaded from the main OpenWhisk servers and instead run on your laptop. You can then, from within the debugger, inspect and modify values. For NodeJS actions, you can even modify code and publish those changes back to the OpenWhisk servers.
-
-The debugger currently supports inspecting an individual action, as well as invocations of this action as it occurs within **sequences** or **rules**. For example, if you have an OpenWhisk rule that fires a given action in response to a some trigger, you can attach to that action and debug, on your laptop, invocations triggered by the cloud.
-
-To see the debugger in action, you can view videos showing wskdb [debugging a live rule](https://youtu.be/ardDxkwjeuA) and [modifying code in your debugger](https://youtu.be/_ZYXr5cUGbs).
-
-## Usage
-
-Start the debug client:
-
-![Startup](docs/startup.png)
-
-You will now be in the `wsdk` REPL. Issue `help` to see the list of available commands. 
-
-Note: the first time you launch `wskdb`, you will experience a ~60 second delay, as the debugger finishes up the installation. This includes pulling in the package dependencies supported by OpenWhisk. These dependencies will allow you to debug actions that require one or more of the [packages supported by OpenWhisk](https://dev-console.stage1.ng.bluemix.net/docs/openwhisk/openwhisk_reference.html#openwhisk_ref_javascript). If you have already initialized the debugger, you can always choose to reinitialize it via `wskdb --reset`; this will reinstall the dependencies.
-
-## Prerequisites
-
-If you wish to debug NodeJS actions, you must currently have a version of NodeJS installed on your local machine that is compatible with the actions you wish to debug. `wskdb` currently does not attempt to employ `nvm` in order to leverage a runtime that matches the action being debugged.
-
-If you wish to debug Swift actions, you must have `swiftc` and `lldb` installed. On MacOS, for example, you can acquire these by installing [XCode](https://itunes.apple.com/us/app/xcode/id497799835?mt=12).
-
-If you wish to debug Python actions, you must have installed a version of Python compatible with 2.7.12. By default, the Python modules that OpenWhisk includes will not be installed locally. If you wish to set things up for debugging Python actions that depend on one or more of these modules, issue `wskdb --python` for your initial invocation. You can add Python support at any time by issuing `wskdb --reset --python`. You needn't pass the `--python` flag every time you use `wskdb`.
-
-## Basic Commands: List, Inspect, Invoke
-
-You can list your actions directly from within the debugger REPL.
-
-![The list command](docs/commands/list.png)]
-
-Note that, in this session, the user had already attached to action `a3`. You may wish to inspect the details of an action, or invoke it prior to attaching. If you haven't yet attached to the action you are invoking, the invocation will proceed as if you weren't in the debugger, and had issued a blocking invocation from the CLI.
-
-![The inspect command](docs/commands/inspect.png)
-![The invoke command](docs/commands/invoke.png "You may pass multiple parameters with -p p1 v1 -p p2 v2")
-
-## Attaching to an action
-
-You can attach to an attach on startup by passing the action name to the initial invocation. Say for example you wish to attach to an action `foo`:
-
-```ShellSession
-% ./wskdb foo
-Attaching to foo
-   Creating action trampoline
-```
-
-You may also choose to launch the debugger and attach to `foo` later:
-
-```ShellSession
-(wskdb) attach foo
-Attaching to foo
-   Creating action trampoline
-```
-
-If you wish to extend the instrumentation to include any containing rules or sequences (in this case, the action occurs in a sequence `seq`):
-
-```ShellSession
-(wskdb) attach foo --all
-Attaching to foo
-   Creating action trampoline
-   Creating sequence splice seq
-```
-
-The short-hand for this is `-a`. 
-
-## Modifying Code
-
-If you are debugging a NodeJS action, you can elect to modify your code during a debug session. If you choose to do so, please be aware of the following bug in either the node-inspector or in NodeJS itself: if you modify the code of your action *after* it has been invoked, then hit Cmd/Ctrl-S to save your changes, this code change will not be reflected in that invocation, even though the code change itself will have registered.
-
-Thus, please make any code changes prior to the debugger entering your action. When the debugger first starts up, you will be at a breakpoint *outside* of your action. This is your opportunity for modifying the code. Make your changes, hit Cmd/Ctrl-S to save them, then click Continue. You will now be in the body of your modified action, and those code changes will be reflected in the return value of the action when you Continue it through to completion.
-
-Once you return to the `wskdb` REPL, you can choose to publish the changes back to the OpenWhisk servers:
-
-![The diff and publish commands](docs/commands/diff_and_publish.png)
-
-## Getting Help
-
-To learn more about the options for each command, you can issue a `-h` request, e.g.
-```ShellSession
-(wskdb) attach -h
-Usage: attach [options]
-
-	--help, -h
-		Displays help information about this script
-
-	--all, -a
-		Instrument the action, plus any rules or sequences in which it takes part
-```
-
-## Choosing CLI versus Browser-based Debugging
-
-By default, `wskdb` will prefer to use a browser-based debugger. If instead you wish to use a command-line debugger, pass the `--use-cli-debugger` option to `wskdb`; the short-hand form of this option is `-c`:
-
-```ShellSession
-% ./wskdb -c
-Welcome to the OpenWhisk Debugger
-    + Favor the CLI for debug sessions over a GUI
-```
-
-## Examples
-
-### Python
-
-This screenshot illustrates an example session of attaching, invoking, and debugging, a Python action.
-
-![Python Example](docs/python/example.png "Routing of a successful invocation")
-
-### NodeJS
-
-In this example, I will use the debugger to inpsect and modify a NodeJS action that prints out a simple hello message. To start debugging a NodeJS action, attach it to the debugger and then invoke. 
-
-<img src="docs/nodejs/node-invokeAction.png" width="600px"/>
-
-As shown in this screenshot, the action takes two parameters: name and place. Their initial values are "Kerry" and "Pittsburgh". 
-
-The debugger will be opened in a browser window. It will first pause at a welcome message. Currently, there are three things the user can do in the dubugger UI. First, the user can change the action's source code by clicking on the code and editing it. Note that currently the user can only edit the code before the debugger entering the main action function. In this example, I change the code to say "hi" instead of "hello". I then save the change and press the "go" button to enter the main function. The second thing the user can do with the debugger is to inspect parameters and change their values using the "Local" tab in the right panel. Here I change the value of the place parameter to "New York". Lastly, the user can set up new breakpoints by clicking on the line number. Here I set a breakpoint at the return statement (line 5). See the recording below for a demo. When the action finishes running, a message will appear to tell the user to return to the CLI to view the result. 
-
-<img src="docs/nodejs/node-debug.gif" width="600px"/>
-
-The function output now becomes "Hi, Kerry from New York.".
-
-<img src="docs/nodejs/node-result.png" width="600px"/>
-
-With the diff command, the user can use the debugger to compare the new and old version of the code. Once satisifed, the user can publish the changes to the cloud to make it live using the publish command. 
-
-<img src="docs/nodejs/node-diffPublish.png" width="600px"/>
-
-
-## Notes on the Architecture
-
-If you are curious as to the inner workings of the debugger, you can read more [here](docs/architecture/architecture.md). In short, `wskdb` operates by graph rewriting. In a way reminiscent of conventional debuggers, `wskdb` will install a *trampoline* that allows insertion of a breakpoint that re-routes invocations to your local machine.
-
-### License
-
-Copyright 2015-2016 IBM Corporation
-
-Licensed under the [Apache License, Version 2.0 (the "License")](http://www.apache.org/licenses/LICENSE-2.0.html).
-
-Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. See the license for the specific language governing permissions and limitations under the license.
-
-### Issues
-
-Report bugs, ask questions and request features [here on GitHub](../../issues).
+For documenation on the client, consult [here](client/README.md).
\ No newline at end of file
diff --git a/client/.gitignore b/client/.gitignore
index 32e7d07..21b5e88 100644
--- a/client/.gitignore
+++ b/client/.gitignore
@@ -1,3 +1,4 @@
 /.initDone
 npm-debug*
-*.pyc
\ No newline at end of file
+*.pyc
+deps/invoker
\ No newline at end of file
diff --git a/client/README.md b/client/README.md
index d72678d..b39e2fc 100644
--- a/client/README.md
+++ b/client/README.md
@@ -1 +1,144 @@
-For basic usage information, please consult the README.md in the enclosing directory.
\ No newline at end of file
+# wskdb: The OpenWhisk Debugger
+
+This project currently supports debugging [OpenWhisk](https://console.ng.bluemix.net/openwhisk) actions written in NodeJS, Python, and Swift. The debugger will arrange things so that the actions you wish to debug will be offloaded from the main OpenWhisk servers and instead run on your laptop. You can then, from within the debugger, inspect and modify values. For NodeJS actions, you can even modify code and publish those changes back to the OpenWhisk servers.
+
+The debugger currently supports inspecting an individual action, as well as invocations of this action as it occurs within **sequences** or **rules**. For example, if you have an OpenWhisk rule that fires a given action in response to a some trigger, you can attach to that action and debug, on your laptop, invocations triggered by the cloud.
+
+To see the debugger in action, you can view videos showing wskdb [debugging a live rule](https://youtu.be/ardDxkwjeuA) and [modifying code in your debugger](https://youtu.be/_ZYXr5cUGbs).
+
+## Usage
+
+Start the debug client:
+
+![Startup](docs/startup.png)
+
+You will now be in the `wsdk` REPL. Issue `help` to see the list of available commands. 
+
+Note: the first time you launch `wskdb`, you will experience a ~60 second delay, as the debugger finishes up the installation. This includes pulling in the package dependencies supported by OpenWhisk. These dependencies will allow you to debug actions that require one or more of the [packages supported by OpenWhisk](https://dev-console.stage1.ng.bluemix.net/docs/openwhisk/openwhisk_reference.html#openwhisk_ref_javascript). If you have already initialized the debugger, you can always choose to reinitialize it via `wskdb --reset`; this will reinstall the dependencies.
+
+## Prerequisites
+
+If you wish to debug NodeJS actions, you must currently have a version of NodeJS installed on your local machine that is compatible with the actions you wish to debug. `wskdb` currently does not attempt to employ `nvm` in order to leverage a runtime that matches the action being debugged.
+
+If you wish to debug Swift actions, you must have `swiftc` and `lldb` installed. On MacOS, for example, you can acquire these by installing [XCode](https://itunes.apple.com/us/app/xcode/id497799835?mt=12).
+
+If you wish to debug Python actions, you must have installed a version of Python compatible with 2.7.12. By default, the Python modules that OpenWhisk includes will not be installed locally. If you wish to set things up for debugging Python actions that depend on one or more of these modules, issue `wskdb --python` for your initial invocation. You can add Python support at any time by issuing `wskdb --reset --python`. You needn't pass the `--python` flag every time you use `wskdb`.
+
+## Basic Commands: List, Inspect, Invoke
+
+You can list your actions directly from within the debugger REPL.
+
+![The list command](docs/commands/list.png)]
+
+Note that, in this session, the user had already attached to action `a3`. You may wish to inspect the details of an action, or invoke it prior to attaching. If you haven't yet attached to the action you are invoking, the invocation will proceed as if you weren't in the debugger, and had issued a blocking invocation from the CLI.
+
+![The inspect command](docs/commands/inspect.png)
+![The invoke command](docs/commands/invoke.png "You may pass multiple parameters with -p p1 v1 -p p2 v2")
+
+## Attaching to an action
+
+You can attach to an attach on startup by passing the action name to the initial invocation. Say for example you wish to attach to an action `foo`:
+
+```ShellSession
+% ./wskdb foo
+Attaching to foo
+   Creating action trampoline
+```
+
+You may also choose to launch the debugger and attach to `foo` later:
+
+```ShellSession
+(wskdb) attach foo
+Attaching to foo
+   Creating action trampoline
+```
+
+If you wish to extend the instrumentation to include any containing rules or sequences (in this case, the action occurs in a sequence `seq`):
+
+```ShellSession
+(wskdb) attach foo --all
+Attaching to foo
+   Creating action trampoline
+   Creating sequence splice seq
+```
+
+The short-hand for this is `-a`. 
+
+## Modifying Code
+
+If you are debugging a NodeJS action, you can elect to modify your code during a debug session. If you choose to do so, please be aware of the following bug in either the node-inspector or in NodeJS itself: if you modify the code of your action *after* it has been invoked, then hit Cmd/Ctrl-S to save your changes, this code change will not be reflected in that invocation, even though the code change itself will have registered.
+
+Thus, please make any code changes prior to the debugger entering your action. When the debugger first starts up, you will be at a breakpoint *outside* of your action. This is your opportunity for modifying the code. Make your changes, hit Cmd/Ctrl-S to save them, then click Continue. You will now be in the body of your modified action, and those code changes will be reflected in the return value of the action when you Continue it through to completion.
+
+Once you return to the `wskdb` REPL, you can choose to publish the changes back to the OpenWhisk servers:
+
+![The diff and publish commands](docs/commands/diff_and_publish.png)
+
+## Getting Help
+
+To learn more about the options for each command, you can issue a `-h` request, e.g.
+```ShellSession
+(wskdb) attach -h
+Usage: attach [options]
+
+	--help, -h
+		Displays help information about this script
+
+	--all, -a
+		Instrument the action, plus any rules or sequences in which it takes part
+```
+
+## Choosing CLI versus Browser-based Debugging
+
+By default, `wskdb` will prefer to use a browser-based debugger. If instead you wish to use a command-line debugger, pass the `--use-cli-debugger` option to `wskdb`; the short-hand form of this option is `-c`:
+
+```ShellSession
+% ./wskdb -c
+Welcome to the OpenWhisk Debugger
+    + Favor the CLI for debug sessions over a GUI
+```
+
+## Examples
+
+### Python
+
+This screenshot illustrates an example session of attaching, invoking, and debugging, a Python action.
+
+![Python Example](docs/python/example.png "Routing of a successful invocation")
+
+### NodeJS
+
+In this example, I will use the debugger to inpsect and modify a NodeJS action that prints out a simple hello message. To start debugging a NodeJS action, attach it to the debugger and then invoke. 
+
+<img src="docs/nodejs/node-invokeAction.png" width="600px"/>
+
+As shown in this screenshot, the action takes two parameters: name and place. Their initial values are "Kerry" and "Pittsburgh". 
+
+The debugger will be opened in a browser window. It will first pause at a welcome message. Currently, there are three things the user can do in the dubugger UI. First, the user can change the action's source code by clicking on the code and editing it. Note that currently the user can only edit the code before the debugger entering the main action function. In this example, I change the code to say "hi" instead of "hello". I then save the change and press the "go" button to enter the main function. The second thing the user can do with the debugger is to inspect parameters and change their values using the "Local" tab in the right panel. Here I change the value of the place parameter to "New York". Lastly, the user can set up new breakpoints by clicking on the line number. Here I set a breakpoint at the return statement (line 5). See the recording below for a demo. When the action finishes running, a message will appear to tell the user to return to the CLI to view the result. 
+
+<img src="docs/nodejs/node-debug.gif" width="600px"/>
+
+The function output now becomes "Hi, Kerry from New York.".
+
+<img src="docs/nodejs/node-result.png" width="600px"/>
+
+With the diff command, the user can use the debugger to compare the new and old version of the code. Once satisifed, the user can publish the changes to the cloud to make it live using the publish command. 
+
+<img src="docs/nodejs/node-diffPublish.png" width="600px"/>
+
+
+## Notes on the Architecture
+
+If you are curious as to the inner workings of the debugger, you can read more [here](docs/architecture/architecture.md). In short, `wskdb` operates by graph rewriting. In a way reminiscent of conventional debuggers, `wskdb` will install a *trampoline* that allows insertion of a breakpoint that re-routes invocations to your local machine.
+
+### License
+
+Copyright 2015-2016 IBM Corporation
+
+Licensed under the [Apache License, Version 2.0 (the "License")](http://www.apache.org/licenses/LICENSE-2.0.html).
+
+Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. See the license for the specific language governing permissions and limitations under the license.
+
+### Issues
+
+Report bugs, ask questions and request features [here on GitHub](../../issues).
diff --git a/client/bin/postinstall b/client/bin/postinstall
new file mode 100755
index 0000000..507d18a
--- /dev/null
+++ b/client/bin/postinstall
@@ -0,0 +1,21 @@
+#!/usr/bin/env node
+
+/**
+  * Copyright 2015-2016 IBM Corporation
+  *
+  * Licensed under the Apache License, Version 2.0 (the "License");
+  * you may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at
+  *
+  * http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+
+require('../lib/init').init()
+    .then(() => console.log("postinstall complete"))
+    .catch(err => console.error(err))
\ No newline at end of file
diff --git a/client/bin/prepublish b/client/bin/prepublish
new file mode 100755
index 0000000..e477cce
--- /dev/null
+++ b/client/bin/prepublish
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+mkdir deps/invoker 2> /dev/null
+cp ../invoker/owdbg-invoker.js deps/invoker
\ No newline at end of file
diff --git a/client/bin/wskdb b/client/bin/wskdb
new file mode 100755
index 0000000..de436da
--- /dev/null
+++ b/client/bin/wskdb
@@ -0,0 +1,19 @@
+#!/usr/bin/env node
+
+/**
+  * Copyright 2015-2016 IBM Corporation
+  *
+  * Licensed under the Apache License, Version 2.0 (the "License");
+  * you may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at
+  *
+  * http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+
+require('../lib/main').main()
diff --git a/client/lib/init.js b/client/lib/init.js
index a0892bb..dd468b9 100644
--- a/client/lib/init.js
+++ b/client/lib/init.js
@@ -81,11 +81,10 @@
 		//
 		args.push('--production');
 	    }
-	    exec('npm', args, { cwd: process.cwd() , stdio: stdio }).on('exit', (err) => {
 		try {
-		    if (err) {
+		    /*		    if (err) {
 			return errDone(err);
-		    }
+			}*/
 	    
 		    //
 		    // here, we install the prerequisities dictated by OpenWhisk nodejs actions
@@ -126,7 +125,7 @@
 		} catch (err) {
 		    return errDone(err);
 		}
-	    });
+
 	} catch (err) {
 	    return errDone(err);
 	}
diff --git a/client/lib/rewriter.js b/client/lib/rewriter.js
index c24595a..702e22a 100644
--- a/client/lib/rewriter.js
+++ b/client/lib/rewriter.js
@@ -139,7 +139,7 @@
 
     createInvoker: function createUpstreamAdapterInvoker_withActionClone(ow, names, actionBeingDebugged, actionBeingDebuggedNamespace) {
 	return new Promise((resolve, reject) => {
-	    fs.readFile(path.join('..', 'invoker', 'owdbg-invoker.js'), (err, codeBuffer) => {
+	    fs.readFile(path.join(__dirname, '..', 'deps', 'invoker', 'owdbg-invoker.js'), (err, codeBuffer) => {
 		if (err) {
 		    reject(err);
 		} else {
diff --git a/client/package.json b/client/package.json
index 0aa99d7..dec4dbd 100644
--- a/client/package.json
+++ b/client/package.json
@@ -1,14 +1,19 @@
 {
-  "name": "wskdb-client",
-  "version": "0.0.1",
-  "description": "OpenWhisk debug client",
+  "name": "openwhisk-debugger",
+  "version": "0.0.10",
+  "description": "A debugger for OpenWhisk",
   "repository": "https://github.ibm.com/nickm/owdbg",
   "main": "client.js",
+  "bin": {
+    "wskdb": "./bin/wskdb"
+  },
   "scripts": {
+    "prepublish": "./bin/prepublish",
+    "postinstall": "./bin/postinstall",
     "test": "./node_modules/.bin/jshint wskdb.js lib/*.js lib/commands/*.js && ./util/scanCode.sh && ava --verbose --serial"
   },
-  "author": "",
-  "license": "ISC",
+  "author": "Nick Mitchell",
+  "license": "Apache-2.0",
   "dependencies": {
     "argv": "0.0.2",
     "colors": "^1.1.2",
diff --git a/client/wskdb b/client/wskdb
index 5aa4fae..b8b2313 100755
--- a/client/wskdb
+++ b/client/wskdb
@@ -16,4 +16,6 @@
 # limitations under the License.
 #
 
+./bin/prepublish
+npm install
 node wskdb.js $@