@tyvm/knowhow 0.0.107 → 0.0.108-dev.4a8ba55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +45 -0
  2. package/package.json +9 -4
  3. package/scripts/publish.sh +86 -0
  4. package/src/agents/base/base.ts +10 -0
  5. package/src/agents/tools/execCommand.ts +49 -6
  6. package/src/agents/tools/index.ts +0 -1
  7. package/src/agents/tools/list.ts +0 -2
  8. package/src/chat/CliChatService.ts +7 -1
  9. package/src/chat/modules/AgentModule.ts +55 -30
  10. package/src/chat/modules/SessionsModule.ts +7 -2
  11. package/src/chat/renderer/CompactRenderer.ts +20 -0
  12. package/src/chat/renderer/ConsoleRenderer.ts +19 -0
  13. package/src/chat/renderer/FancyRenderer.ts +19 -0
  14. package/src/chat/renderer/types.ts +11 -0
  15. package/src/cli.ts +79 -661
  16. package/src/clients/anthropic.ts +19 -16
  17. package/src/clients/types.ts +23 -4
  18. package/src/cloudWorker.ts +75 -1
  19. package/src/commands/agent.ts +246 -0
  20. package/src/commands/misc.ts +169 -0
  21. package/src/commands/modules.ts +182 -0
  22. package/src/commands/services.ts +72 -0
  23. package/src/commands/workers.ts +160 -0
  24. package/src/config.ts +37 -0
  25. package/src/index.ts +18 -0
  26. package/src/plugins/embedding.ts +11 -6
  27. package/src/plugins/plugins.ts +0 -21
  28. package/src/plugins/vim.ts +5 -16
  29. package/src/processors/JsonCompressor.ts +6 -6
  30. package/src/services/KnowhowClient.ts +22 -2
  31. package/src/services/S3.ts +10 -0
  32. package/src/services/modules/index.ts +58 -49
  33. package/src/services/modules/types.ts +4 -0
  34. package/src/tunnel.ts +216 -0
  35. package/src/types.ts +0 -1
  36. package/src/worker.ts +105 -312
  37. package/src/workers/auth/WsMiddleware.ts +99 -0
  38. package/src/workers/auth/authMiddleware.ts +104 -0
  39. package/src/workers/auth/types.ts +14 -2
  40. package/src/workers/tools/index.ts +2 -0
  41. package/src/workers/tools/reloadConfig.ts +84 -0
  42. package/tests/services/WorkerReloadConfig.test.ts +141 -0
  43. package/tests/unit/modules/moduleLoading.test.ts +0 -25
  44. package/tests/unit/plugins/pluginLoading.test.ts +0 -85
  45. package/ts_build/package.json +9 -4
  46. package/ts_build/src/agents/base/base.js +11 -0
  47. package/ts_build/src/agents/base/base.js.map +1 -1
  48. package/ts_build/src/agents/tools/execCommand.d.ts +1 -1
  49. package/ts_build/src/agents/tools/execCommand.js +39 -5
  50. package/ts_build/src/agents/tools/execCommand.js.map +1 -1
  51. package/ts_build/src/agents/tools/index.d.ts +0 -1
  52. package/ts_build/src/agents/tools/index.js +0 -1
  53. package/ts_build/src/agents/tools/index.js.map +1 -1
  54. package/ts_build/src/agents/tools/list.js +0 -2
  55. package/ts_build/src/agents/tools/list.js.map +1 -1
  56. package/ts_build/src/chat/CliChatService.js +10 -1
  57. package/ts_build/src/chat/CliChatService.js.map +1 -1
  58. package/ts_build/src/chat/modules/AgentModule.d.ts +1 -1
  59. package/ts_build/src/chat/modules/AgentModule.js +39 -19
  60. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  61. package/ts_build/src/chat/modules/SessionsModule.js +7 -2
  62. package/ts_build/src/chat/modules/SessionsModule.js.map +1 -1
  63. package/ts_build/src/chat/renderer/CompactRenderer.d.ts +4 -0
  64. package/ts_build/src/chat/renderer/CompactRenderer.js +16 -0
  65. package/ts_build/src/chat/renderer/CompactRenderer.js.map +1 -1
  66. package/ts_build/src/chat/renderer/ConsoleRenderer.d.ts +4 -0
  67. package/ts_build/src/chat/renderer/ConsoleRenderer.js +16 -0
  68. package/ts_build/src/chat/renderer/ConsoleRenderer.js.map +1 -1
  69. package/ts_build/src/chat/renderer/FancyRenderer.d.ts +4 -0
  70. package/ts_build/src/chat/renderer/FancyRenderer.js +16 -0
  71. package/ts_build/src/chat/renderer/FancyRenderer.js.map +1 -1
  72. package/ts_build/src/chat/renderer/types.d.ts +2 -0
  73. package/ts_build/src/cli.js +40 -519
  74. package/ts_build/src/cli.js.map +1 -1
  75. package/ts_build/src/clients/anthropic.d.ts +5 -5
  76. package/ts_build/src/clients/anthropic.js +19 -16
  77. package/ts_build/src/clients/anthropic.js.map +1 -1
  78. package/ts_build/src/clients/types.d.ts +5 -2
  79. package/ts_build/src/cloudWorker.d.ts +9 -0
  80. package/ts_build/src/cloudWorker.js +36 -0
  81. package/ts_build/src/cloudWorker.js.map +1 -1
  82. package/ts_build/src/commands/agent.d.ts +6 -0
  83. package/ts_build/src/commands/agent.js +229 -0
  84. package/ts_build/src/commands/agent.js.map +1 -0
  85. package/ts_build/src/commands/misc.d.ts +10 -0
  86. package/ts_build/src/commands/misc.js +195 -0
  87. package/ts_build/src/commands/misc.js.map +1 -0
  88. package/ts_build/src/commands/modules.d.ts +3 -0
  89. package/ts_build/src/commands/modules.js +160 -0
  90. package/ts_build/src/commands/modules.js.map +1 -0
  91. package/ts_build/src/commands/services.d.ts +5 -0
  92. package/ts_build/src/commands/services.js +86 -0
  93. package/ts_build/src/commands/services.js.map +1 -0
  94. package/ts_build/src/commands/workers.d.ts +6 -0
  95. package/ts_build/src/commands/workers.js +163 -0
  96. package/ts_build/src/commands/workers.js.map +1 -0
  97. package/ts_build/src/config.d.ts +1 -0
  98. package/ts_build/src/config.js +32 -0
  99. package/ts_build/src/config.js.map +1 -1
  100. package/ts_build/src/index.d.ts +1 -0
  101. package/ts_build/src/index.js +17 -1
  102. package/ts_build/src/index.js.map +1 -1
  103. package/ts_build/src/plugins/embedding.js +4 -3
  104. package/ts_build/src/plugins/embedding.js.map +1 -1
  105. package/ts_build/src/plugins/plugins.d.ts +0 -2
  106. package/ts_build/src/plugins/plugins.js +0 -11
  107. package/ts_build/src/plugins/plugins.js.map +1 -1
  108. package/ts_build/src/plugins/vim.js +3 -9
  109. package/ts_build/src/plugins/vim.js.map +1 -1
  110. package/ts_build/src/processors/JsonCompressor.js +4 -4
  111. package/ts_build/src/processors/JsonCompressor.js.map +1 -1
  112. package/ts_build/src/services/KnowhowClient.d.ts +12 -0
  113. package/ts_build/src/services/KnowhowClient.js +11 -0
  114. package/ts_build/src/services/KnowhowClient.js.map +1 -1
  115. package/ts_build/src/services/S3.js +7 -0
  116. package/ts_build/src/services/S3.js.map +1 -1
  117. package/ts_build/src/services/modules/index.d.ts +33 -0
  118. package/ts_build/src/services/modules/index.js +38 -42
  119. package/ts_build/src/services/modules/index.js.map +1 -1
  120. package/ts_build/src/services/modules/types.d.ts +4 -0
  121. package/ts_build/src/tunnel.d.ts +27 -0
  122. package/ts_build/src/tunnel.js +112 -0
  123. package/ts_build/src/tunnel.js.map +1 -0
  124. package/ts_build/src/types.d.ts +0 -1
  125. package/ts_build/src/types.js.map +1 -1
  126. package/ts_build/src/worker.d.ts +1 -4
  127. package/ts_build/src/worker.js +59 -227
  128. package/ts_build/src/worker.js.map +1 -1
  129. package/ts_build/src/workers/auth/WsMiddleware.d.ts +8 -0
  130. package/ts_build/src/workers/auth/WsMiddleware.js +65 -0
  131. package/ts_build/src/workers/auth/WsMiddleware.js.map +1 -0
  132. package/ts_build/src/workers/auth/authMiddleware.d.ts +3 -0
  133. package/ts_build/src/workers/auth/authMiddleware.js +60 -0
  134. package/ts_build/src/workers/auth/authMiddleware.js.map +1 -0
  135. package/ts_build/src/workers/auth/types.d.ts +8 -1
  136. package/ts_build/src/workers/tools/index.d.ts +2 -0
  137. package/ts_build/src/workers/tools/index.js +4 -1
  138. package/ts_build/src/workers/tools/index.js.map +1 -1
  139. package/ts_build/src/workers/tools/reloadConfig.d.ts +14 -0
  140. package/ts_build/src/workers/tools/reloadConfig.js +48 -0
  141. package/ts_build/src/workers/tools/reloadConfig.js.map +1 -0
  142. package/ts_build/tests/services/WorkerReloadConfig.test.d.ts +1 -0
  143. package/ts_build/tests/services/WorkerReloadConfig.test.js +86 -0
  144. package/ts_build/tests/services/WorkerReloadConfig.test.js.map +1 -0
  145. package/ts_build/tests/unit/modules/moduleLoading.test.js +0 -19
  146. package/ts_build/tests/unit/modules/moduleLoading.test.js.map +1 -1
  147. package/ts_build/tests/unit/plugins/pluginLoading.test.js +0 -65
  148. package/ts_build/tests/unit/plugins/pluginLoading.test.js.map +1 -1
  149. package/src/agents/tools/executeScript/README.md +0 -94
  150. package/src/agents/tools/executeScript/definition.ts +0 -79
  151. package/src/agents/tools/executeScript/examples/dependency-injection-validation.ts +0 -272
  152. package/src/agents/tools/executeScript/examples/quick-test.ts +0 -74
  153. package/src/agents/tools/executeScript/examples/serialization-test.ts +0 -321
  154. package/src/agents/tools/executeScript/examples/test-runner.ts +0 -197
  155. package/src/agents/tools/executeScript/index.ts +0 -98
  156. package/src/services/script-execution/SandboxContext.ts +0 -282
  157. package/src/services/script-execution/ScriptExecutor.ts +0 -441
  158. package/src/services/script-execution/ScriptPolicy.ts +0 -194
  159. package/src/services/script-execution/ScriptTracer.ts +0 -249
  160. package/src/services/script-execution/types.ts +0 -134
  161. package/ts_build/src/agents/tools/executeScript/definition.d.ts +0 -2
  162. package/ts_build/src/agents/tools/executeScript/definition.js +0 -76
  163. package/ts_build/src/agents/tools/executeScript/definition.js.map +0 -1
  164. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.d.ts +0 -18
  165. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js +0 -192
  166. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js.map +0 -1
  167. package/ts_build/src/agents/tools/executeScript/examples/quick-test.d.ts +0 -3
  168. package/ts_build/src/agents/tools/executeScript/examples/quick-test.js +0 -64
  169. package/ts_build/src/agents/tools/executeScript/examples/quick-test.js.map +0 -1
  170. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.d.ts +0 -15
  171. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js +0 -266
  172. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js.map +0 -1
  173. package/ts_build/src/agents/tools/executeScript/examples/test-runner.d.ts +0 -4
  174. package/ts_build/src/agents/tools/executeScript/examples/test-runner.js +0 -208
  175. package/ts_build/src/agents/tools/executeScript/examples/test-runner.js.map +0 -1
  176. package/ts_build/src/agents/tools/executeScript/index.d.ts +0 -28
  177. package/ts_build/src/agents/tools/executeScript/index.js +0 -72
  178. package/ts_build/src/agents/tools/executeScript/index.js.map +0 -1
  179. package/ts_build/src/services/script-execution/SandboxContext.d.ts +0 -34
  180. package/ts_build/src/services/script-execution/SandboxContext.js +0 -189
  181. package/ts_build/src/services/script-execution/SandboxContext.js.map +0 -1
  182. package/ts_build/src/services/script-execution/ScriptExecutor.d.ts +0 -19
  183. package/ts_build/src/services/script-execution/ScriptExecutor.js +0 -269
  184. package/ts_build/src/services/script-execution/ScriptExecutor.js.map +0 -1
  185. package/ts_build/src/services/script-execution/ScriptPolicy.d.ts +0 -28
  186. package/ts_build/src/services/script-execution/ScriptPolicy.js +0 -115
  187. package/ts_build/src/services/script-execution/ScriptPolicy.js.map +0 -1
  188. package/ts_build/src/services/script-execution/ScriptTracer.d.ts +0 -19
  189. package/ts_build/src/services/script-execution/ScriptTracer.js +0 -186
  190. package/ts_build/src/services/script-execution/ScriptTracer.js.map +0 -1
  191. package/ts_build/src/services/script-execution/types.d.ts +0 -108
  192. package/ts_build/src/services/script-execution/types.js +0 -3
  193. package/ts_build/src/services/script-execution/types.js.map +0 -1
@@ -0,0 +1,182 @@
1
+ import { Command } from "commander";
2
+ import { execSync } from "child_process";
3
+ import { getConfig, getGlobalConfig, updateConfig, updateGlobalConfig } from "../config";
4
+
5
+ // Default built-in modules that `knowhow modules setup` adds to the config.
6
+ export const BUILTIN_MODULES = [
7
+ "@tyvm/knowhow-module-script",
8
+ "@tyvm/knowhow-module-terminal",
9
+ ];
10
+
11
+ export function addModulesCommand(program: Command): void {
12
+ const modulesCmd = program
13
+ .command("modules")
14
+ .description("Manage knowhow modules (install, add to config, list)");
15
+
16
+ modulesCmd
17
+ .command("setup")
18
+ .description(
19
+ "Add default built-in modules to your config and install them via npm"
20
+ )
21
+ .option("--global", "Use the global config (~/.knowhow/knowhow.json)")
22
+ .action(async (opts) => {
23
+ try {
24
+ const isGlobal: boolean = opts.global ?? false;
25
+ const cfg = isGlobal ? await getGlobalConfig() : await getConfig();
26
+ const configLabel = isGlobal
27
+ ? "~/.knowhow/knowhow.json"
28
+ : ".knowhow/knowhow.json";
29
+
30
+ if (!cfg.modules) cfg.modules = [];
31
+
32
+ const toAdd = BUILTIN_MODULES.filter(
33
+ (m) => !cfg.modules!.includes(m)
34
+ );
35
+
36
+ if (toAdd.length === 0) {
37
+ console.log(
38
+ `✅ All default modules are already in ${configLabel}. Nothing to do.`
39
+ );
40
+ return;
41
+ }
42
+
43
+ // Install packages that are not local file paths
44
+ for (const mod of toAdd) {
45
+ if (!mod.startsWith(".") && !mod.startsWith("/")) {
46
+ console.log(`📦 Installing ${mod}...`);
47
+ const installFlag = isGlobal ? "-g" : "";
48
+ execSync(`npm install ${installFlag} ${mod}`, {
49
+ stdio: "inherit",
50
+ encoding: "utf-8",
51
+ });
52
+ }
53
+ cfg.modules!.push(mod);
54
+ console.log(`✅ Added ${mod} to ${configLabel}`);
55
+ }
56
+
57
+ if (isGlobal) {
58
+ await updateGlobalConfig(cfg);
59
+ } else {
60
+ await updateConfig(cfg);
61
+ }
62
+
63
+ console.log(
64
+ `\n🎉 Setup complete! ${toAdd.length} module(s) added to ${configLabel}`
65
+ );
66
+ } catch (error) {
67
+ console.error("Error during modules setup:", error.message ?? error);
68
+ process.exit(1);
69
+ }
70
+ });
71
+
72
+ modulesCmd
73
+ .command("install [module]")
74
+ .description(
75
+ "Install a module via npm and add it to your config. " +
76
+ "If no module name is given, installs all modules already in the config."
77
+ )
78
+ .option("--global", "Use the global config (~/.knowhow/knowhow.json)")
79
+ .action(async (moduleName: string | undefined, opts) => {
80
+ try {
81
+ const isGlobal: boolean = opts.global ?? false;
82
+ const cfg = isGlobal ? await getGlobalConfig() : await getConfig();
83
+ const configLabel = isGlobal
84
+ ? "~/.knowhow/knowhow.json"
85
+ : ".knowhow/knowhow.json";
86
+
87
+ if (!cfg.modules) cfg.modules = [];
88
+
89
+ if (!moduleName) {
90
+ // No module specified — install everything already in the config
91
+ const installable = cfg.modules.filter(
92
+ (m) => !m.startsWith(".") && !m.startsWith("/")
93
+ );
94
+ if (installable.length === 0) {
95
+ console.log(
96
+ `ℹ No installable modules found in ${configLabel}.`
97
+ );
98
+ return;
99
+ }
100
+ console.log(
101
+ `📦 Installing ${installable.length} module(s) from ${configLabel}...`
102
+ );
103
+ const installFlag = isGlobal ? "-g" : "";
104
+ for (const mod of installable) {
105
+ console.log(` 📦 Installing ${mod}...`);
106
+ execSync(`npm install ${installFlag} ${mod}`, {
107
+ stdio: "inherit",
108
+ encoding: "utf-8",
109
+ });
110
+ console.log(` ✅ Installed ${mod}`);
111
+ }
112
+ console.log(`\n🎉 All modules installed!`);
113
+ return;
114
+ }
115
+
116
+ // Install the specified module
117
+ const installFlag = isGlobal ? "-g" : "";
118
+ console.log(`📦 Installing ${moduleName}...`);
119
+ execSync(`npm install ${installFlag} ${moduleName}`, {
120
+ stdio: "inherit",
121
+ encoding: "utf-8",
122
+ });
123
+ console.log(`✅ Installed ${moduleName}`);
124
+
125
+ // Add to config if not already there
126
+ if (!cfg.modules.includes(moduleName)) {
127
+ cfg.modules.push(moduleName);
128
+ if (isGlobal) {
129
+ await updateGlobalConfig(cfg);
130
+ } else {
131
+ await updateConfig(cfg);
132
+ }
133
+ console.log(`✅ Added ${moduleName} to ${configLabel}`);
134
+ } else {
135
+ console.log(`ℹ ${moduleName} is already in ${configLabel}`);
136
+ }
137
+ } catch (error) {
138
+ console.error("Error during module install:", error.message ?? error);
139
+ process.exit(1);
140
+ }
141
+ });
142
+
143
+ modulesCmd
144
+ .command("list")
145
+ .description("List all modules in your config")
146
+ .option("--global", "Show global config modules only")
147
+ .action(async (opts) => {
148
+ try {
149
+ const isGlobal: boolean = opts.global ?? false;
150
+ const globalCfg = await getGlobalConfig();
151
+ const localCfg = isGlobal ? null : await getConfig();
152
+
153
+ const globalModules = globalCfg.modules || [];
154
+ const localModules = localCfg?.modules || [];
155
+
156
+ if (isGlobal) {
157
+ console.log(`\n🌐 Global modules (~/.knowhow/knowhow.json):`);
158
+ if (globalModules.length === 0) {
159
+ console.log(" (none)");
160
+ } else {
161
+ globalModules.forEach((m, i) => console.log(` ${i + 1}. ${m}`));
162
+ }
163
+ } else {
164
+ console.log(`\n🌐 Global modules (~/.knowhow/knowhow.json):`);
165
+ if (globalModules.length === 0) {
166
+ console.log(" (none)");
167
+ } else {
168
+ globalModules.forEach((m, i) => console.log(` ${i + 1}. ${m}`));
169
+ }
170
+ console.log(`\n📁 Local modules (.knowhow/knowhow.json):`);
171
+ if (localModules.length === 0) {
172
+ console.log(" (none)");
173
+ } else {
174
+ localModules.forEach((m, i) => console.log(` ${i + 1}. ${m}`));
175
+ }
176
+ }
177
+ } catch (error) {
178
+ console.error("Error listing modules:", error.message ?? error);
179
+ process.exit(1);
180
+ }
181
+ });
182
+ }
@@ -0,0 +1,72 @@
1
+ import { includedTools } from "../agents/tools/list";
2
+ import * as allTools from "../agents/tools";
3
+ import { LazyToolsService, services } from "../services";
4
+ import { agents } from "../agents";
5
+ import { ModulesService } from "../services/modules";
6
+
7
+ /**
8
+ * Shared service setup used by commands that need full services (chat, agent, worker, etc.)
9
+ */
10
+ export async function setupServices() {
11
+ const {
12
+ Agents,
13
+ Mcp,
14
+ Clients,
15
+ Tools: AllTools,
16
+ Embeddings,
17
+ Plugins,
18
+ MediaProcessor,
19
+ } = services();
20
+ const Tools = new LazyToolsService();
21
+
22
+ Tools.setContext({
23
+ ...AllTools.getContext(),
24
+ });
25
+
26
+ const agentContext: import("../agents/base/base").AgentContext = {
27
+ ...services(),
28
+ Tools,
29
+ };
30
+
31
+ const { Researcher, Developer, Patcher, Setup } = agents({
32
+ ...agentContext,
33
+ });
34
+
35
+ Agents.registerAgent(Researcher);
36
+ Agents.registerAgent(Patcher);
37
+ Agents.registerAgent(Developer);
38
+ Agents.registerAgent(Setup);
39
+ Agents.loadAgentsFromConfig(agentContext);
40
+
41
+ Tools.defineTools(includedTools, allTools);
42
+
43
+ Tools.addContext("Mcp", Mcp);
44
+
45
+ Agents.setAgentContext(agentContext);
46
+
47
+ console.log("🔌 Connecting to MCP...");
48
+ try {
49
+ await Mcp.connectToConfigured(Tools);
50
+ } catch (mcpError) {
51
+ const msg = mcpError instanceof Error ? mcpError.message : String(mcpError);
52
+ console.warn(
53
+ `⚠ Some MCP servers failed to connect (continuing without them): ${msg}`
54
+ );
55
+ }
56
+ console.log("Connecting to clients...");
57
+ await Clients.registerConfiguredModels();
58
+ console.log("✓ Services are set up and ready to go!");
59
+
60
+ console.log("📦 Loading modules from config...");
61
+ const modulesService = new ModulesService();
62
+ await modulesService.loadModulesFromConfig({
63
+ Agents,
64
+ Embeddings,
65
+ Plugins,
66
+ Clients,
67
+ Tools,
68
+ MediaProcessor,
69
+ });
70
+
71
+ return { Tools, Clients };
72
+ }
@@ -0,0 +1,160 @@
1
+ import { Command } from "commander";
2
+ import { worker } from "../worker";
3
+ import { TUNNEL_MINIMAL_TOOLS } from "../tunnel";
4
+ import { fileSync } from "../fileSync";
5
+ import {
6
+ startAllWorkers,
7
+ listWorkerPaths,
8
+ unregisterWorkerPath,
9
+ clearWorkerRegistry,
10
+ } from "../workerRegistry";
11
+
12
+ export function addWorkerCommand(program: Command): void {
13
+ program
14
+ .command("worker")
15
+ .description(
16
+ "Start worker process and optionally register current directory"
17
+ )
18
+ .option("--register", "Register current directory as a worker path")
19
+ .option(
20
+ "--share",
21
+ "Share this worker with your organization (allows other users to use it)"
22
+ )
23
+ .option("--unshare", "Make this worker private (only you can use it)")
24
+ .option("--sandbox", "Run worker in a Docker container for isolation")
25
+ .option(
26
+ "--no-sandbox",
27
+ "Run worker directly on host (disable sandbox mode)"
28
+ )
29
+ .option("--passkey", "Set up passkey authentication for this worker")
30
+ .option("--passkey-reset", "Remove passkey authentication requirement")
31
+ .action(async (options) => {
32
+ const { setupServices } = await import("./services");
33
+ await setupServices();
34
+ await worker(options);
35
+ });
36
+ }
37
+
38
+ export function addWorkersCommand(program: Command): void {
39
+ program
40
+ .command("workers")
41
+ .description("Manage and start all registered workers")
42
+ .option("--list", "List all registered worker paths")
43
+ .option("--unregister <path>", "Unregister a worker path")
44
+ .option("--clear", "Clear all registered worker paths")
45
+ .action(async (options) => {
46
+ try {
47
+ if (options.list) {
48
+ const workers = await listWorkerPaths();
49
+ if (workers.length === 0) {
50
+ console.log("No workers registered.");
51
+ console.log(
52
+ "\nTo register a worker, run 'knowhow worker --register' from the worker directory."
53
+ );
54
+ } else {
55
+ console.log(`Registered workers (${workers.length}):`);
56
+ workers.forEach((workerPath, index) => {
57
+ console.log(` ${index + 1}. ${workerPath}`);
58
+ });
59
+ }
60
+ return;
61
+ }
62
+
63
+ if (options.unregister) {
64
+ await unregisterWorkerPath(options.unregister);
65
+ return;
66
+ }
67
+
68
+ if (options.clear) {
69
+ await clearWorkerRegistry();
70
+ return;
71
+ }
72
+
73
+ // Default action: start all workers
74
+ const { setupServices } = await import("./services");
75
+ await setupServices();
76
+ await startAllWorkers();
77
+ } catch (error) {
78
+ console.error("Error managing workers:", error);
79
+ process.exit(1);
80
+ }
81
+ });
82
+ }
83
+
84
+ export function addTunnelCommand(program: Command): void {
85
+ program
86
+ .command("tunnel")
87
+ .description(
88
+ "Start a minimal worker with tunnel enabled: exposes local ports to the cloud. " +
89
+ "Registers essential tools (unlock, lock, listAllowedPorts) so the backend is aware of the worker and ports. " +
90
+ "If passkey auth is configured, the tunnel is locked until unlocked via tool call or WebSocket auth protocol."
91
+ )
92
+ .option(
93
+ "--share",
94
+ "Share this tunnel with your organization (allows other users to use it)"
95
+ )
96
+ .option("--unshare", "Make this tunnel private (only you can use it)")
97
+ .action(async (options) => {
98
+ console.log("🌐 Starting tunnel (minimal worker) mode...");
99
+ console.log(` Tools: ${TUNNEL_MINIMAL_TOOLS.join(", ")}`);
100
+ await worker({
101
+ ...options,
102
+ allowedTools: TUNNEL_MINIMAL_TOOLS,
103
+ });
104
+ });
105
+ }
106
+
107
+ export function addFilesCommand(program: Command): void {
108
+ program
109
+ .command("files")
110
+ .description(
111
+ "Sync files between local filesystem and Knowhow FS (uses fileMounts config)"
112
+ )
113
+ .option("--upload", "Force upload direction for all mounts")
114
+ .option("--download", "Force download direction for all mounts")
115
+ .option("--config <path>", "Path to knowhow.json", "./knowhow.json")
116
+ .option("--dry-run", "Print what would be synced without doing it")
117
+ .action(async (options) => {
118
+ try {
119
+ await fileSync(options);
120
+ } catch (error) {
121
+ console.error("Error syncing files:", error);
122
+ process.exit(1);
123
+ }
124
+ });
125
+ }
126
+
127
+ export function addCloudWorkerCommand(program: Command): void {
128
+ program
129
+ .command("cloudworker")
130
+ .description("Create or sync a cloud worker with your local knowhow config")
131
+ .option(
132
+ "--create",
133
+ "Create a new cloud worker with synced config and files"
134
+ )
135
+ .option(
136
+ "--push <uid>",
137
+ "Push/sync local config and files to an existing cloud worker"
138
+ )
139
+ .option(
140
+ "--pull <id>",
141
+ "Pull the latest workerConfigJson from a cloud worker and update local config"
142
+ )
143
+ .option("--name <name>", "Name for the cloud worker (used with --create)")
144
+ .option("--dry-run", "Print what would be synced without doing it")
145
+ .action(async (options) => {
146
+ try {
147
+ const { cloudWorker, pullCloudWorkerConfig } = await import(
148
+ "../cloudWorker"
149
+ );
150
+ if (options.pull) {
151
+ await pullCloudWorkerConfig({ id: options.pull });
152
+ } else {
153
+ await cloudWorker(options);
154
+ }
155
+ } catch (error) {
156
+ console.error("Error running cloudworker:", error);
157
+ process.exit(1);
158
+ }
159
+ });
160
+ }
package/src/config.ts CHANGED
@@ -168,6 +168,27 @@ export async function init() {
168
168
  console.log("Initializing global knowhow config at ~/.knowhow");
169
169
  const globalConfigDir = await ensureGlobalConfigDir();
170
170
 
171
+ // Ensure the script module is registered in the global config so that
172
+ // `knowhow script` and the `executeScript` tool are available everywhere.
173
+ const SCRIPT_MODULE = "@tyvm/knowhow-module-script";
174
+ const globalConfigPath = path.join(globalConfigDir, "knowhow.json");
175
+ try {
176
+ const rawGlobal = fs.existsSync(globalConfigPath)
177
+ ? fs.readFileSync(globalConfigPath, "utf8")
178
+ : JSON.stringify(defaultConfig, null, 2);
179
+ const globalConf = JSON.parse(rawGlobal) as Config;
180
+ if (!globalConf.modules) {
181
+ globalConf.modules = [];
182
+ }
183
+ if (!globalConf.modules.includes(SCRIPT_MODULE)) {
184
+ globalConf.modules.push(SCRIPT_MODULE);
185
+ fs.writeFileSync(globalConfigPath, JSON.stringify(globalConf, null, 2));
186
+ console.log(`✅ Added ${SCRIPT_MODULE} to ~/.knowhow/knowhow.json modules`);
187
+ }
188
+ } catch (e) {
189
+ console.warn(`⚠ Could not update global config to add script module:`, e);
190
+ }
191
+
171
192
  // create the folder structure
172
193
  console.log("Initializing local knowhow config at ./.knowhow");
173
194
  await mkdir(".knowhow", { recursive: true });
@@ -287,6 +308,22 @@ export async function getGlobalConfig(): Promise<Config> {
287
308
  }
288
309
  }
289
310
 
311
+ export async function updateGlobalConfig(config: Config) {
312
+ if (!config || typeof config !== "object") {
313
+ throw new Error("Invalid config object");
314
+ }
315
+
316
+ const globalConfigDir = getGlobalConfigDir();
317
+ await mkdir(globalConfigDir, { recursive: true });
318
+ const globalConfigPath = path.join(globalConfigDir, "knowhow.json");
319
+
320
+ if (fs.existsSync(globalConfigPath)) {
321
+ await fs.promises.copyFile(globalConfigPath, globalConfigPath + ".bak");
322
+ }
323
+
324
+ await writeFile(globalConfigPath, JSON.stringify(config, null, 2));
325
+ }
326
+
290
327
  export async function migrateConfig() {
291
328
  // Apply migrations, used to keep config structure up to date.
292
329
  if (!fs.existsSync(".knowhow/knowhow.json")) {
package/src/index.ts CHANGED
@@ -53,6 +53,7 @@ export * as ai from "./ai";
53
53
 
54
54
  // Export module system types for external modules
55
55
  export * from "./services/modules/types";
56
+ export { ModulesService } from "./services/modules";
56
57
  // Export plugin types for external plugins
57
58
  export { PluginBase } from "./plugins/PluginBase";
58
59
  export { PluginMeta, Plugin, PluginContext } from "./plugins/types";
@@ -138,6 +139,23 @@ export async function upload() {
138
139
  if (!source.remoteId) {
139
140
  throw new Error("remoteId is required for knowhow uploads");
140
141
  }
142
+ // Warn if the local embeddingModel differs from the one stored on the backend
143
+ try {
144
+ const remoteEmbedding = await knowhowApiClient.getOrgEmbedding(source.remoteId);
145
+ const localModel = config.embeddingModel || EmbeddingModels.openai.EmbeddingAda2;
146
+ const remoteModel = remoteEmbedding?.modelName;
147
+ if (remoteModel && remoteModel !== localModel) {
148
+ console.warn(
149
+ `⚠️ WARNING: Embedding model mismatch for "${remoteEmbedding.name}" (remoteId: ${source.remoteId}).\n` +
150
+ ` Local config.embeddingModel: ${localModel}\n` +
151
+ ` Backend embedding modelName: ${remoteModel}\n` +
152
+ ` Vectors generated with different models are not comparable — search results will be incorrect.\n` +
153
+ ` Update your config.embeddingModel to "${remoteModel}" or update the backend embedding to "${localModel}".`
154
+ );
155
+ }
156
+ } catch (e) {
157
+ // Non-fatal — don't block upload if metadata fetch fails
158
+ }
141
159
  const url = await knowhowApiClient.getPresignedUploadUrl(source);
142
160
  console.log("Uploading to", url);
143
161
  await AwsS3.uploadToPresignedUrl(url, source.output);
@@ -20,9 +20,12 @@ export class EmbeddingPlugin extends PluginBase {
20
20
 
21
21
  constructor(context) {
22
22
  super(context);
23
-
23
+
24
24
  // Subscribe to file:post-edit events
25
- this.context.Events.on("file:post-edit", this.handleFilePostEdit.bind(this));
25
+ this.context.Events.on(
26
+ "file:post-edit",
27
+ this.handleFilePostEdit.bind(this)
28
+ );
26
29
  }
27
30
 
28
31
  async embed() {
@@ -68,10 +71,12 @@ export class EmbeddingPlugin extends PluginBase {
68
71
  this.log(`Reading entry ${entry.id}`);
69
72
  }
70
73
 
71
- const contextLength = JSON.stringify(context).split(" ").length;
74
+ const ids = context.map((entry) => entry.id);
75
+
76
+ const contextLength = JSON.stringify(ids).split(" ").length;
72
77
  this.log(`Found ${context.length} entries. Loading ${contextLength} words`);
73
78
 
74
- return `EMBEDDING PLUGIN: Our knowledgebase contains this information which can be used to answer the question:
75
- ${JSON.stringify(context)}`;
79
+ return `EMBEDDING PLUGIN: Our knowledgebase indicates these embedding entries may be related to the question:
80
+ ${JSON.stringify(ids)}`;
76
81
  }
77
- }
82
+ }
@@ -1,5 +1,4 @@
1
1
  import { Plugin, PluginContext } from "./types";
2
- import { Config } from "../types";
3
2
  import { VimPlugin } from "./vim";
4
3
  import { LinterPlugin } from "./LinterPlugin";
5
4
  import { LanguagePlugin } from "./language";
@@ -49,26 +48,6 @@ export class PluginService {
49
48
  return instance.meta.key;
50
49
  }
51
50
 
52
- /**
53
- * Load plugins from config's pluginPackages map.
54
- * Each entry maps a plugin key to an npm package name or file path.
55
- * Errors are caught and logged as warnings without crashing.
56
- */
57
- async loadPluginsFromConfig(config: Config): Promise<void> {
58
- const pluginPackages = config.pluginPackages || {};
59
- for (const [key, spec] of Object.entries(pluginPackages)) {
60
- try {
61
- await this.loadPlugin(spec);
62
- } catch (error) {
63
- this.events?.log(
64
- "PluginService",
65
- `Failed to load plugin "${key}" from "${spec}": ${error instanceof Error ? error.message : error}`,
66
- "warn"
67
- );
68
- }
69
- }
70
- }
71
-
72
51
  /** Disable a plugin by its key; returns `true` if found. */
73
52
  disablePlugin(key: string): boolean {
74
53
  const p = this.pluginMap.get(key);
@@ -73,22 +73,11 @@ export class VimPlugin extends PluginBase {
73
73
 
74
74
  async call() {
75
75
  const vimFiles = await this.getVimFiles();
76
- const fileContents = await Promise.all(
77
- vimFiles.map(async (f) => {
78
- const loaded = await this.getFileContents(f);
79
-
80
- const preview =
81
- loaded.content.length > 1000
82
- ? loaded.content.slice(0, 1000) +
83
- "... file trimmed, read file for full content"
84
- : loaded.content;
85
-
86
- return {
87
- sourceFile: loaded.filePath,
88
- content: loaded.content.slice(0, 1000),
89
- };
90
- })
91
- );
76
+ const fileContents = vimFiles.map((f) => {
77
+ return {
78
+ sourceFile: f,
79
+ };
80
+ });
92
81
  if (fileContents.length === 0) {
93
82
  return "VIM PLUGIN: No files open in vim";
94
83
  }
@@ -382,7 +382,7 @@ export class JsonCompressor {
382
382
  i + currentChunk.length - 1
383
383
  }]\nPreview: ${chunkString.substring(0, 100)}...\n[Use ${
384
384
  this.toolName
385
- } tool with key "${key}" to retrieve this chunk]`;
385
+ } tool with key "${key}" to retrieve this chunk]\n[TIP: try jqToolResponse,grepToolResponse,tailToolResponse to filter/search/map without repeated ${this.toolName} calls - especially useful for JSON data]`;
386
386
  finalArray.unshift(stub); // Add stub to the start of our final result.
387
387
 
388
388
  currentChunk = [];
@@ -415,11 +415,11 @@ export class JsonCompressor {
415
415
 
416
416
  // Store objects on FIRST occurrence so second occurrence can reference it
417
417
  // We increment seenCount above, so after increment:
418
- // seenCount=1: first occurrence (just incremented from 0 to 1), store it
419
- // seenCount>=2: we already stored it on first occurrence, should be in dedup map
418
+ // seenCount=0: first occurrence (before increment), store it
419
+ // seenCount>=1: we already stored it on first occurrence, should be in dedup map
420
420
  // Note: This means we store proactively - first occurrence gets stored AND returned in full
421
421
  // Second+ occurrences will find it in the dedup map and return a reference
422
- const isFirstOccurrence = seenCount === 1;
422
+ const isFirstOccurrence = seenCount === 0;
423
423
 
424
424
  // Process the object - apply low-signal detection
425
425
  const objWithLowSignalCompressed = this.compressObjectWithLowSignalDetection(obj, path);
@@ -453,7 +453,7 @@ export class JsonCompressor {
453
453
  result
454
454
  ).join(", ")}\nPreview: ${objectAsString.substring(0, 200)}...\n[Use ${
455
455
  this.toolName
456
- } tool with key "${key}" to retrieve full content]`;
456
+ } tool with key "${key}" to retrieve full content]\n[TIP: try jqToolResponse,grepToolResponse,tailToolResponse to filter/search/map without repeated ${this.toolName} calls - especially useful for JSON data]`;
457
457
  }
458
458
  return result;
459
459
  }
@@ -486,7 +486,7 @@ export class JsonCompressor {
486
486
  200
487
487
  )}...\n[Use ${
488
488
  this.toolName
489
- } tool with key "${key}" to retrieve full content]`;
489
+ } tool with key "${key}" to retrieve full content]\n[TIP: try jqToolResponse,grepToolResponse,tailToolResponse to filter/search/map without repeated ${this.toolName} calls - especially useful for JSON data]`;
490
490
  }
491
491
  return obj;
492
492
  }
@@ -171,11 +171,9 @@ export class KnowhowSimpleClient {
171
171
  try {
172
172
  this.jwtValidated = true;
173
173
  const response = await this.me();
174
-
175
174
  const user = response.data.user;
176
175
  const orgs = user.orgs;
177
176
  const orgId = response.data.orgId;
178
-
179
177
  const currentOrg = orgs.find((org) => {
180
178
  return org.organizationId === orgId;
181
179
  });
@@ -227,6 +225,17 @@ export class KnowhowSimpleClient {
227
225
  return presignedUrl;
228
226
  }
229
227
 
228
+ async getOrgEmbedding(id: string) {
229
+ await this.checkJwt();
230
+ const resp = await http.get(
231
+ `${this.baseUrl}/api/org-embeddings/${id}`,
232
+ {
233
+ headers: this.headers,
234
+ }
235
+ );
236
+ return resp.data as { id: string; modelName: string; name: string; [key: string]: unknown };
237
+ }
238
+
230
239
  async updateEmbeddingMetadata(
231
240
  id: string,
232
241
  data: {
@@ -718,6 +727,17 @@ export class KnowhowSimpleClient {
718
727
  );
719
728
  }
720
729
 
730
+ /**
731
+ * Get a single cloud worker by ID
732
+ */
733
+ async getCloudWorker(id: string) {
734
+ await this.checkJwt();
735
+ return http.get<{ id: string; name: string; status: string; workerConfigJson?: Record<string, unknown> }>(
736
+ `${this.baseUrl}/api/cloud-workers/${id}`,
737
+ { headers: this.headers }
738
+ );
739
+ }
740
+
721
741
  /**
722
742
  * Update an existing cloud worker
723
743
  */