Skip to content

Development

Rob Royce edited this page Jan 10, 2024 · 8 revisions

There are two main entry points for development: src/kc_electron and src/kc_angular

  • kc_electron contains all of the files for setting up Electron, IPC (inter-process communication) between the main and renderer processes, all functionality that deals directly with the Operating System (OS), and the servers used for the Chrome extension and chatting via the OpenAI API.
  • kc_angular contains all of the Angular (UI) code that runs in the renderer process.

Getting Started

The following steps should be followed closely to ensure a proper development environment. Minor variations in dependency versions are most likely fine, but only those listed below have been tested and verified.

Clone the Repository

Using HTTPS

git clone https://github.com/KnowledgeCanvas/knowledge.git
cd knowledge

Using SSH

git clone [email protected]:KnowledgeCanvas/knowledge.git
cd knowledge

Install Node, NPM, and Yarn

The following versions were used at the time of this writing:

  • Node.js: 18.16.0
  • NPM: 9.5.1 (automatically installed with Node)
  • Yarn: 3.2.4 (berry)

Note: starting with Yarn v4, the process for configuring Yarn has changed. Previously, the command to set the appropriate Yarn version was yarn set version berry. However, with Yarn v4 the same command does not work properly and we now must use yarn set version 3.2.4. Be sure to use the appropriate command depending on your installed version of Yarn.

After cloning the repo and installing Node.js and Yarn, run the following commands (from the repo root directory) to ensure you have the correct Yarn plugins.

Dependency Installation and Configuration

Install node modules

yarn set version 3.2.4
yarn plugin import typescript
yarn plugin import workspace-tools
yarn install

Note: the contents of the file .yarnrc.yml should be the following:

nodeLinker: node-modules

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
    spec: "@yarnpkg/plugin-typescript"
  - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
    spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.1.1.cjs

However, it has been pointed out that there are issues with Yarn that cause the build to fail. The best way to get around this issue is to remove the original .yarnrc.yml, run the above commands, then prepend the line nodeLinker: node-modules before running yarn install. This is a temporary workaround.

Copy tokenizer

This step is only required if you want to use the Chat feature while running the app in development mode.

Copy the bg_tiktoken.wasm file from node_modules to the Resources folder:

cp ./node_modules/@dqbd/tiktoken/tiktoken_bg.wasm ./Resources/

Build and Run

yarn build
yarn start

Using Watchers for Real-Time Development

This will allow you to refresh the application and see changes in real-time, without having to recompile Electron and Angular code (the watchers auto-compile as files are changed/saved).

  1. Follow the steps above, up to the build step
  2. Build, run, and watch the project:
yarn watch-main-dev &
yarn watch-electron-dev &
yarn start &

Note: changes made in kc_electron require you to restart the app, even when using watchers. This is because, once opened, Electron will not propagate changes to the existing window.

Note: changes made in kc_angular do not require you to restart the app, you can simply reload the page using CMD+R (MacOS) or CTRL+R / F5 (Linux/Windows)

You can also choose to run yarn watch-main and yarn watch-electron (without the -dev), but they will take longer to transpile and build, and no source map will be produced.

Cleanup and Purging

The following commands provide convenience methods for removing installed dependencies and generated build files. This is useful for ensuring a blank-slate, and are always run before producing distributable binaries.

Clean the project and delete build files

yarn clean

Purge dependencies and clear caches

yarn purge

Create distributable binaries for MacOS, Windows and Linux

  1. Clean and reinstall dependencies, then build the project:
yarn clean 
yarn purge
yarn install
yarn build
  1. Create the distributables:
yarn dist-all