fnloom 0.1.0 → 0.2.0

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 (113) hide show
  1. package/README.md +31 -18
  2. package/package.json +2 -7
  3. package/packages/build/package.json +1 -1
  4. package/packages/cli/package.json +1 -1
  5. package/packages/cli/src/commands/available.ts +63 -22
  6. package/packages/cli/src/commands/install.ts +86 -28
  7. package/packages/cli/src/index.ts +3 -2
  8. package/packages/cli/src/local.ts +6 -0
  9. package/packages/cli/src/premade.ts +80 -0
  10. package/packages/core/package.json +1 -1
  11. package/packages/hub/package.json +1 -1
  12. package/packages/hub/src/link/process.ts +6 -1
  13. package/packages/sdk/package.json +1 -1
  14. package/packages/web/package.json +1 -1
  15. package/premade/claude.zip +0 -0
  16. package/premade/database.zip +0 -0
  17. package/premade/web.zip +0 -0
  18. package/scripts/dev-env.ts +4 -4
  19. package/scripts/stack.ts +42 -27
  20. package/scripts/start.ts +26 -16
  21. package/systems/api/package.json +1 -1
  22. package/systems/code/package.json +1 -1
  23. package/systems/embedder/package.json +1 -1
  24. package/systems/fs/package.json +1 -1
  25. package/systems/google-calendar/package.json +1 -1
  26. package/systems/input/package.json +1 -1
  27. package/systems/mcp/package.json +1 -1
  28. package/systems/ollama/package.json +1 -1
  29. package/systems/schedule/package.json +1 -1
  30. package/systems/template/package.json +1 -1
  31. package/systems/widgets/package.json +1 -1
  32. package/systems/claude/client/FleetPage.vue +0 -132
  33. package/systems/claude/client/NewSessionForm.vue +0 -62
  34. package/systems/claude/client/SessionList.vue +0 -64
  35. package/systems/claude/client/SessionPage.vue +0 -199
  36. package/systems/claude/client/TaskList.vue +0 -61
  37. package/systems/claude/client/fakes.ts +0 -186
  38. package/systems/claude/client/host.ts +0 -23
  39. package/systems/claude/client/index.ts +0 -15
  40. package/systems/claude/client/logic.ts +0 -270
  41. package/systems/claude/client/state.ts +0 -344
  42. package/systems/claude/package.json +0 -23
  43. package/systems/claude/server/agent-sdk.ts +0 -379
  44. package/systems/claude/server/driver.ts +0 -153
  45. package/systems/claude/server/env.ts +0 -64
  46. package/systems/claude/server/fake-driver.ts +0 -112
  47. package/systems/claude/server/fleet.ts +0 -376
  48. package/systems/claude/server/impl.ts +0 -568
  49. package/systems/claude/server/index.ts +0 -8
  50. package/systems/claude/server/main.ts +0 -38
  51. package/systems/claude/server/preview.ts +0 -76
  52. package/systems/claude/server/questions.ts +0 -117
  53. package/systems/claude/server/transcript.ts +0 -83
  54. package/systems/claude/shared/index.ts +0 -262
  55. package/systems/claude/shared/session.ts +0 -284
  56. package/systems/claude/shared/shapes.ts +0 -106
  57. package/systems/claude/system.json +0 -18
  58. package/systems/claude/tsconfig.json +0 -6
  59. package/systems/database/package.json +0 -25
  60. package/systems/database/server/author.ts +0 -41
  61. package/systems/database/server/authoring.ts +0 -322
  62. package/systems/database/server/catalog.ts +0 -117
  63. package/systems/database/server/compile.ts +0 -332
  64. package/systems/database/server/dialects.ts +0 -17
  65. package/systems/database/server/drivers/database.ts +0 -71
  66. package/systems/database/server/drivers/index.ts +0 -23
  67. package/systems/database/server/drivers/postgres.ts +0 -157
  68. package/systems/database/server/drivers/sqlite.ts +0 -151
  69. package/systems/database/server/drivers/sqlserver.ts +0 -176
  70. package/systems/database/server/env.ts +0 -35
  71. package/systems/database/server/fixture.ts +0 -169
  72. package/systems/database/server/impl.ts +0 -793
  73. package/systems/database/server/index.ts +0 -7
  74. package/systems/database/server/instance.ts +0 -398
  75. package/systems/database/server/main.ts +0 -47
  76. package/systems/database/server/pick.ts +0 -97
  77. package/systems/database/server/queries.ts +0 -390
  78. package/systems/database/server/results.ts +0 -39
  79. package/systems/database/server/schema.ts +0 -59
  80. package/systems/database/server/table-fns.ts +0 -237
  81. package/systems/database/server/types.ts +0 -253
  82. package/systems/database/shared/index.ts +0 -544
  83. package/systems/database/shared/shapes.ts +0 -413
  84. package/systems/database/system.json +0 -14
  85. package/systems/database/tsconfig.json +0 -6
  86. package/systems/web/client/ReadView.vue +0 -110
  87. package/systems/web/client/SearchView.vue +0 -215
  88. package/systems/web/client/StatusChip.vue +0 -38
  89. package/systems/web/client/fakes.ts +0 -48
  90. package/systems/web/client/index.ts +0 -15
  91. package/systems/web/client/view.ts +0 -131
  92. package/systems/web/package.json +0 -22
  93. package/systems/web/server/chrome.ts +0 -121
  94. package/systems/web/server/crawl.ts +0 -333
  95. package/systems/web/server/env.ts +0 -63
  96. package/systems/web/server/guard.ts +0 -60
  97. package/systems/web/server/http.ts +0 -89
  98. package/systems/web/server/impl.ts +0 -203
  99. package/systems/web/server/index.ts +0 -71
  100. package/systems/web/server/loader.ts +0 -104
  101. package/systems/web/server/main.ts +0 -70
  102. package/systems/web/server/mentions.ts +0 -111
  103. package/systems/web/server/problem.ts +0 -72
  104. package/systems/web/server/renderer.ts +0 -243
  105. package/systems/web/server/robots.ts +0 -75
  106. package/systems/web/server/searches.ts +0 -29
  107. package/systems/web/server/tavily.ts +0 -144
  108. package/systems/web/server/testing.ts +0 -165
  109. package/systems/web/server/uploads.ts +0 -33
  110. package/systems/web/shared/index.ts +0 -343
  111. package/systems/web/shared/urls.ts +0 -60
  112. package/systems/web/system.json +0 -15
  113. package/systems/web/tsconfig.json +0 -6
package/README.md CHANGED
@@ -9,7 +9,7 @@ the harness itself (from a clone of the repository), see the README in the [repo
9
9
 
10
10
  ## What you need
11
11
 
12
- - **Node.js 22.18 or later** (with npm). Check with `node -v`.
12
+ - **Node.js 22.21 or later** (with npm; installed systems reach the network through the hub's proxy, which needs 22.21). Check with `node -v`.
13
13
  - **A model provider.** An [OpenRouter](https://openrouter.ai) key is the quickest (`OPENROUTER_API_KEY`); AWS
14
14
  Bedrock and a local [Ollama](https://ollama.com) work too. You can also add one after the first start.
15
15
 
@@ -22,6 +22,11 @@ npm install -g fnloom
22
22
  This puts the `fnloom` command on your PATH. To keep it inside one folder instead, run
23
23
  `npm install fnloom` there and use `npx fnloom …` in place of `fnloom …`.
24
24
 
25
+ The package carries the hub, the app, the command line and the lightweight premade systems. The heavier systems
26
+ (database, web, claude) come as small packages inside it whose own dependencies (the SQLite driver built for your
27
+ machine, puppeteer and the Chrome it downloads, the Claude Agent SDK) are fetched only when you install that system (see
28
+ [Premade systems](#premade-systems)).
29
+
25
30
  ## Start it
26
31
 
27
32
  Open a terminal in the folder you want the agent to work with (the **fs** system serves that folder's files to it),
@@ -31,7 +36,8 @@ then:
31
36
  fnloom start
32
37
  ```
33
38
 
34
- On the first start it makes the admin account and prints everything you need:
39
+ It starts the hub, the app and the lightweight premade systems (fs, input, code, schedule and api). On the first
40
+ start it makes the admin account and prints everything you need:
35
41
 
36
42
  ```text
37
43
  The harness is running.
@@ -57,7 +63,7 @@ for your review.
57
63
  | `--port <n>` | `HARNESS_PORT` | 4300 | the hub and the web app it serves (http and https on the same port) |
58
64
  | `--data <dir>` | `HARNESS_DATA` | `~/.harness` | the database, files, keys, logs and installed systems |
59
65
  | `--root <dir>` | `HARNESS_DEV_ROOT` | the folder you start in | the folder the fs system serves |
60
- | `--systems <list>` | `HARNESS_DEV_ONLY` | see below | what to run: `hub` plus system names (`fs`, `input`, `widgets`, `code`, `web-system`, `calendar`, `embedder`, `schedule`, `database`, `ollama`, `claude`) |
66
+ | `--systems <list>` | `HARNESS_DEV_ONLY` | see below | what to run: `hub` plus lightweight system names (`fs`, `input`, `code`, `schedule`, `api`, `widgets`, `calendar`, `embedder`); `--systems hub` runs no systems. The heavy ones (database, web, claude) are installed instead, and then start with the hub |
61
67
  | | `HARNESS_ADMIN_EMAIL`, `HARNESS_ADMIN_PASSWORD` | made on the first start | your own admin account instead of the generated one (set before the first start) |
62
68
  | | `OPENROUTER_API_KEY` | none | configures the OpenRouter provider on the first start |
63
69
  | | `HARNESS_DEFAULT_MODEL` | `openrouter/auto` | the chat agent's model until an admin picks one |
@@ -80,24 +86,26 @@ proxy) works too: see "Installing the app, and HTTPS" in [`docs/harness.md`](htt
80
86
 
81
87
  ## Premade systems
82
88
 
83
- The harness comes with these systems. `fnloom start` runs the first group; install the others when you want them.
84
- `fnloom system available` prints the same list.
89
+ The harness comes with these systems. `fnloom start` runs the lightweight ones in the first group (they need
90
+ nothing beyond what the hub already has); install the others when you want them. The heavy ones (database, web and
91
+ claude) fetch their own dependencies when you install them, into that system's folder in the data folder, so a
92
+ machine that never installs web never downloads puppeteer's Chrome. `fnloom system available` prints the same list.
85
93
 
86
94
  | System | Started by `fnloom start` | What it adds |
87
95
  |---|---|---|
88
96
  | `fs` | always | files and folders as resources; read, write, search, and shell commands with approval |
89
97
  | `input` | always | forms the agent asks you to fill in |
90
- | `widgets` | always | charts and tables drawn from fns, saved as widgets |
91
98
  | `code` | always | fns written as small programs that call other fns |
92
- | `web` | when `TAVILY_API_KEY` is set | web search ([Tavily](https://tavily.com)), page reading and site crawls |
99
+ | `schedule` | always | fns that run on a schedule (every day at 9, once next Friday) |
100
+ | `api` | always | fns that call web APIs, written from a service's OpenAPI document |
93
101
  | `google-calendar` | when `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` are set | each person's own Google Calendar |
94
102
  | `embedder` | when `HARNESS_EMBEDDER_URL` is set | embeddings from an EmbeddingGemma service, for search and suggestions |
95
- | `schedule` | no: install it | fns that run on a schedule (every day at 9, once next Friday) |
96
- | `database` | no: install it | SQL databases (SQLite, Postgres, SQL Server): tables as types, kept queries as fns |
97
- | `api` | no: install it | fns that call web APIs, written from a service's OpenAPI document |
103
+ | `database` | no: install it (brings `widgets`; fetches the SQLite driver built for your machine) | SQL databases (SQLite, Postgres, SQL Server): tables as types, kept queries as fns |
104
+ | `widgets` | no: comes with `database` | charts and tables drawn from database queries, saved as widgets |
105
+ | `web` | no: install it (fetches puppeteer and its Chrome) | web search ([Tavily](https://tavily.com)), page reading and site crawls |
106
+ | `claude` | no: install it (fetches the Claude Agent SDK) | Claude Code sessions on this machine, managed from the harness |
98
107
  | `mcp` | no: add servers in the app | MCP servers' tools as fns, prompts as commands |
99
108
  | `ollama` | no: install it | runs (or talks to) Ollama and offers its models |
100
- | `claude` | no: install it | Claude Code sessions on this machine, managed from the harness |
101
109
 
102
110
  ### Installing one
103
111
 
@@ -107,8 +115,9 @@ With `fnloom start` running, in another terminal:
107
115
  fnloom system install <name> [--config <file.json>]
108
116
  ```
109
117
 
110
- `<name>` is a premade system's name from the table. The hub installs it from the copy that came with the harness,
111
- pairs it, gives it the config, starts it, and starts it again every time the hub starts. The command waits until it
118
+ `<name>` is a premade system's name from the table. The hub installs it from the copy that came with the harness
119
+ (for database, web and claude it also runs `npm install` of their own dependencies into the system's folder, which
120
+ takes a minute), pairs it, gives it the config, starts it, and starts it again every time the hub starts. The command waits until it
112
121
  has connected and says so. If the hub runs on another port or keeps its data somewhere else, say so:
113
122
  `--hub http://127.0.0.1:4620` and `HARNESS_DATA=<the data folder>` (that is where it finds `admin.json`). It then
114
123
  puts the system live and says so.
@@ -119,9 +128,11 @@ A system that needs config and was installed without it connects and waits: fill
119
128
 
120
129
  The config each one takes:
121
130
 
122
- - **schedule**: nothing. `fnloom system install schedule`. Its limits (schedules per person, firings per day, the
131
+ - **schedule**: nothing (it starts with `fnloom start`). Its limits (schedules per person, firings per day, the
123
132
  shortest gap between firings) all have defaults; change them on its page in the app.
124
- - **database**: one instance per database. For a new SQLite file in the system's data folder:
133
+ - **database**: one instance per database; the first install also installs **widgets** (charts and tables over its
134
+ queries) when the hub doesn't have it. Installing widgets on its own works too, and says it wants database. For a
135
+ new SQLite file in the system's data folder:
125
136
 
126
137
  ```json
127
138
  {
@@ -137,10 +148,12 @@ The config each one takes:
137
148
  `fnloom system install database --config database.json`. `data: "read-only"` and `schema: "none"` keep it from
138
149
  changing anything; `connection` can also be an existing SQLite file, Postgres or SQL Server (the system's page in
139
150
  the app has a form for every field).
140
- - **api**: nothing. `fnloom system install api`. Services are added in the app (**Admin › API services**) or by
151
+ - **api**: nothing (it starts with `fnloom start`). Services are added in the app (**Admin › API services**) or by
141
152
  asking the agent.
142
- - **web**: a Tavily key, `{ "tavilyKey": "tvly-…" }`, or set `TAVILY_API_KEY` before `fnloom start` and it runs
143
- without installing.
153
+ - **web**: a Tavily key for search, `fnloom system install web --config web.json` with `{ "tavilyKey": "tvly-…" }`
154
+ (an installed system doesn't see the hub's environment, so `TAVILY_API_KEY` there doesn't reach it). Without one
155
+ it installs and reads pages; search says it needs the key until you set it on its page in the app. Installing it fetches puppeteer into its folder, and puppeteer
156
+ downloads the Chrome it drives into its own cache (`~/.cache/puppeteer`) unless one is there already.
144
157
  - **google-calendar**: a Google OAuth client (a "Web application" client) with `<hub>/connect/callback` among its
145
158
  redirect URIs: `{ "clientId": "…", "clientSecret": "…", "hubUrl": "http://127.0.0.1:4300" }`. Each person then
146
159
  connects their own calendar on the Calendar page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnloom",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A web-based agent harness you run yourself: one hub that owns every model call, person and permission, and systems that add fns, types, resources and screens.",
5
5
  "keywords": [
6
6
  "agent",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "type": "module",
20
20
  "engines": {
21
- "node": ">=22.18"
21
+ "node": ">=22.21"
22
22
  },
23
23
  "bin": {
24
24
  "fnloom": "packages/cli/bin/harness.mjs"
@@ -35,10 +35,8 @@
35
35
  "@aeye/ollama": "0.10.1",
36
36
  "@aeye/openai": "0.10.1",
37
37
  "@aeye/openrouter": "0.10.1",
38
- "@aeye/query": "0.10.1",
39
38
  "@aeye/resources": "0.10.1",
40
39
  "@aeye/schema": "0.10.1",
41
- "@anthropic-ai/claude-agent-sdk": "0.3.323",
42
40
  "@ayepi/auth": "0.6.0",
43
41
  "@ayepi/cache": "0.6.0",
44
42
  "@ayepi/codec": "0.6.0",
@@ -62,10 +60,7 @@
62
60
  "jszip": "3.10.2",
63
61
  "kysely": "0.28.19",
64
62
  "mammoth": "1.13.0",
65
- "mssql": "12.7.14",
66
63
  "pdf-parse": "1.1.4",
67
- "pg": "8.23.1",
68
- "puppeteer": "25.16.0",
69
64
  "qrcode": "1.5.4",
70
65
  "sqlite-vec": "0.1.9",
71
66
  "tsx": "4.23.15",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "name": "@harness/build",
11
11
  "private": true,
12
- "version": "0.1.0",
12
+ "version": "0.2.0",
13
13
  "license": "Apache-2.0",
14
14
  "type": "module",
15
15
  "description": "Building systems: typecheck, a self-contained server bundle, client renderers, the context folder check and the bundle scan. Shared by the CLI and fs.",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "name": "@harness/cli",
15
15
  "private": true,
16
- "version": "0.1.0",
16
+ "version": "0.2.0",
17
17
  "license": "Apache-2.0",
18
18
  "type": "module",
19
19
  "description": "The harness CLI: make, build, pack and install systems, export their data, and bridge a hub MCP to stdio.",
@@ -1,49 +1,92 @@
1
1
  /**
2
- * `harness system available`: the premade systems this copy of the harness carries (`systems/` beside the CLI), each
3
- * with what it is, whether `harness start` runs it, and the command that installs it. Read from their `system.json`,
4
- * with no hub involved.
2
+ * `harness system available`: the premade systems this copy of the harness carries, each with what it is, whether
3
+ * `harness start` runs it, and the command that installs it. They are the folders in `systems/` beside the CLI and, in
4
+ * the published package, the package zips in `premade/` (the heavy systems, which bring their own npm dependencies
5
+ * when installed: see `premade.ts`). Read from their `system.json`, with no hub involved.
5
6
  */
6
7
  import { join, sep } from 'node:path';
8
+ import { PACKAGE_MANIFEST_FILE } from '@harness/core';
9
+ import { unzip } from '@harness/hub/package';
7
10
  import { z } from 'zod';
8
11
  import { command, type CliIo } from '../command.ts';
9
- import { BUNDLED_SYSTEMS_DIR, CLI_NAME, NOT_INSTALLABLE } from '../local.ts';
10
-
11
- /** When `harness start` runs a premade system (by folder name); the others are installed on demand. */
12
- export const STARTED_BY_DEFAULT: Readonly<Record<string, string>> = {
13
- fs: 'always', input: 'always', widgets: 'always', code: 'always',
14
- web: 'when TAVILY_API_KEY is set', 'google-calendar': 'when GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET are set', embedder: 'when HARNESS_EMBEDDER_URL is set',
15
- };
12
+ import { BUNDLED_SYSTEMS_DIR, CLI_NAME, NOT_INSTALLABLE, PREMADE_DIR } from '../local.ts';
13
+ import { PREMADE, startedWhen } from '../premade.ts';
16
14
 
17
15
  const SystemJson = z.object({ name: z.string(), description: z.string().default(''), instances: z.enum(['one', 'many']).default('one') });
18
16
 
19
- /** A premade system: its folder name and what its `system.json` says. */
17
+ /** The largest premade package zip read for its `system.json`. */
18
+ const MAX_ZIP = 256 * 1024 * 1024;
19
+
20
+ /** A premade system: its folder name, where it is (a folder, or a package zip), and what its `system.json` says. */
20
21
  export interface BundledSystem {
21
22
  readonly folder: string;
23
+ /** Its folder, or its package zip (`premade/<name>.zip`) when the folder is not here. */
22
24
  readonly dir: string;
25
+ readonly packaged: boolean;
23
26
  readonly name: string;
24
27
  readonly description: string;
25
28
  readonly instances: 'one' | 'many';
26
29
  }
27
30
 
28
- /** The premade systems in `dir` (every folder with a `system.json`, but the template), by folder name. */
29
- export async function bundledSystems(io: Pick<CliIo, 'files'>, dir: string = BUNDLED_SYSTEMS_DIR): Promise<BundledSystem[]> {
30
- const manifests = (await io.files.walk(dir, ['node_modules', 'dist', 'client', 'server', 'shared', 'context']))
31
- .filter((path) => path.slice(dir.length + 1).split(sep).length === 2 && path.endsWith(`${sep}system.json`));
31
+ /** The premade package zip for a name, in `premadeDir`. */
32
+ const zipOf = (premadeDir: string, name: string): string => join(premadeDir, `${name}.zip`);
33
+
34
+ /** What a package zip's `system.json` says, if it reads. */
35
+ async function zippedSystemJson(io: Pick<CliIo, 'files'>, path: string): Promise<z.infer<typeof SystemJson> | undefined> {
36
+ try {
37
+ const entry = unzip(await io.files.read(path), MAX_ZIP).find((e) => e.path === PACKAGE_MANIFEST_FILE);
38
+ if (entry === undefined) { return undefined; }
39
+ const parsed = SystemJson.safeParse(JSON.parse(new TextDecoder().decode(entry.bytes)));
40
+ return parsed.success ? parsed.data : undefined;
41
+ } catch {
42
+ return undefined;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * The premade systems: every folder in `dir` with a `system.json` (but the template), and every package zip in
48
+ * `premadeDir` with no folder of its name, by folder name.
49
+ */
50
+ export async function bundledSystems(io: Pick<CliIo, 'files'>, dir: string = BUNDLED_SYSTEMS_DIR, premadeDir: string = PREMADE_DIR): Promise<BundledSystem[]> {
51
+ const manifests = (await io.files.stat(dir))?.kind === 'folder'
52
+ ? (await io.files.walk(dir, ['node_modules', 'dist', 'client', 'server', 'shared', 'context']))
53
+ .filter((path) => path.slice(dir.length + 1).split(sep).length === 2 && path.endsWith(`${sep}system.json`))
54
+ : [];
32
55
  const found: BundledSystem[] = [];
33
56
  for (const path of manifests) {
34
57
  const folder = path.slice(dir.length + 1).split(sep)[0] ?? '';
35
58
  if (NOT_INSTALLABLE.has(folder)) { continue; }
36
59
  const parsed = SystemJson.safeParse(JSON.parse(await io.files.readText(path)));
37
- if (parsed.success) { found.push({ folder, dir: join(dir, folder), ...parsed.data }); }
60
+ if (parsed.success) { found.push({ folder, dir: join(dir, folder), packaged: false, ...parsed.data }); }
61
+ }
62
+ for (const name of Object.keys(PREMADE)) {
63
+ if (found.some((s) => s.folder === name) || (await io.files.stat(zipOf(premadeDir, name)))?.kind !== 'file') { continue; }
64
+ const read = await zippedSystemJson(io, zipOf(premadeDir, name));
65
+ if (read !== undefined) { found.push({ folder: name, dir: zipOf(premadeDir, name), packaged: true, ...read }); }
38
66
  }
39
67
  return found.sort((a, b) => a.folder.localeCompare(b.folder));
40
68
  }
41
69
 
42
- /** The premade system a bare name means (`database`), if this copy of the harness carries one by that folder name. */
43
- export async function bundledSystem(io: Pick<CliIo, 'files'>, name: string, dir: string = BUNDLED_SYSTEMS_DIR): Promise<string | undefined> {
70
+ /**
71
+ * The premade system a bare name means (`database`), if this copy of the harness carries one by that name: its folder
72
+ * when it is here (the repository, and the lightweight systems in the package), else its package zip.
73
+ */
74
+ export async function bundledSystem(io: Pick<CliIo, 'files'>, name: string, dir: string = BUNDLED_SYSTEMS_DIR, premadeDir: string = PREMADE_DIR): Promise<string | undefined> {
44
75
  if (!/^[a-z][a-z0-9-]*$/.test(name) || NOT_INSTALLABLE.has(name)) { return undefined; }
45
76
  const folder = join(dir, name);
46
- return (await io.files.stat(join(folder, 'system.json')))?.kind === 'file' ? folder : undefined;
77
+ if ((await io.files.stat(join(folder, 'system.json')))?.kind === 'file') { return folder; }
78
+ return PREMADE[name] !== undefined && (await io.files.stat(zipOf(premadeDir, name)))?.kind === 'file' ? zipOf(premadeDir, name) : undefined;
79
+ }
80
+
81
+ /** How a premade system gets onto a hub, in words. */
82
+ function howToGet(folder: string): string {
83
+ const started = startedWhen(folder);
84
+ if (started !== undefined) { return `started by ${CLI_NAME} start ${started}`; }
85
+ if (folder === 'mcp') { return 'add MCP servers in the app (Admin > MCP servers): the hub runs one for each'; }
86
+ const premade = PREMADE[folder];
87
+ const along = premade?.with === undefined ? '' : ` (installs ${premade.with.join(', ')} with it)`;
88
+ const own = premade?.package === true ? ', which fetches its own dependencies' : '';
89
+ return `${CLI_NAME} system install ${folder}${own}${along}`;
47
90
  }
48
91
 
49
92
  export const availableCommand = command({
@@ -56,10 +99,8 @@ export const availableCommand = command({
56
99
  if (systems.length === 0) { io.out.warn(`no premade systems in ${BUNDLED_SYSTEMS_DIR}`); return 1; }
57
100
  const width = Math.max(...systems.map((s) => s.folder.length));
58
101
  for (const system of systems) {
59
- const started = STARTED_BY_DEFAULT[system.folder];
60
- const how = started === undefined ? `${CLI_NAME} system install ${system.folder}` : `started by ${CLI_NAME} start ${started}`;
61
102
  io.out.line(`${system.folder.padEnd(width)} ${system.description}${system.instances === 'many' ? ' (one instance per target)' : ''}`);
62
- io.out.line(`${''.padEnd(width)} ${how}`);
103
+ io.out.line(`${''.padEnd(width)} ${howToGet(system.folder)}`);
63
104
  }
64
105
  return 0;
65
106
  },
@@ -3,17 +3,21 @@
3
3
  * install a system on a running hub, which pairs it, configures it and starts it beside itself. A zip is uploaded and
4
4
  * installed as a package (a fleet package takes `--instance`; `--data` restores a data export into the new
5
5
  * instance); a folder is installed in place; the bare name of a premade system this harness carries (`database`,
6
- * `schedule`: `harness system available` lists them) installs that folder; anything else is an npm package
7
- * (`name@version`; give a version, `database@latest`, for an npm package named like a premade system). It then waits
8
- * for the system to connect and says where it got to.
6
+ * `schedule`: `harness system available` lists them) installs that system: its folder, or in the published package
7
+ * its package zip for the heavy ones (the hub then installs the npm packages it left out into the system's own
8
+ * folder). A premade system installed by name goes live, and brings the systems `premade.ts` says go with it
9
+ * (database brings widgets). Anything else is an npm package (`name@version`; give a version, `database@latest`, for
10
+ * an npm package named like a premade system). It then waits for the system to connect and says where it got to.
9
11
  */
10
12
  import { basename, resolve } from 'node:path';
11
- import { InstanceName, Json, instanceLabel, type InstallSource, type SystemName, type SystemStatus } from '@harness/core';
13
+ import { InstanceName, Json, SystemName, instanceLabel, type InstallSource, type SystemStatus } from '@harness/core';
12
14
  import { z } from 'zod';
13
15
  import { HUB_OPTIONS, command, type CliIo } from '../command.ts';
14
16
  import type { HubSession } from '../hub.ts';
15
17
  import { bundledSystem } from './available.ts';
16
18
  import { goLiveWhenPaired, liveApi } from '../live.ts';
19
+ import { CLI_NAME } from '../local.ts';
20
+ import { PREMADE } from '../premade.ts';
17
21
 
18
22
  /** The mime type of the zips the CLI uploads. */
19
23
  const ZIP = 'application/zip';
@@ -35,6 +39,12 @@ async function statusOf(hub: HubSession, system: SystemName, instance: InstanceN
35
39
  return (await hub.api.call('instances', { system }).catch(() => [])).find((i) => i.instance === instance)?.status;
36
40
  }
37
41
 
42
+ /** Whether the hub has a system installed (any status but removed). */
43
+ async function isInstalled(hub: HubSession, system: string): Promise<boolean> {
44
+ const status = await hub.api.call('system', { system: SystemName.parse(system) }).then((view) => view.status, () => undefined);
45
+ return status !== undefined && status !== 'removed';
46
+ }
47
+
38
48
  /** Wait until a system (or one instance) is connected or needs config, or `wait` passes; says where it got to. */
39
49
  export async function waitForSystem(io: CliIo, hub: HubSession, target: { system: SystemName; instance?: InstanceName | undefined }, wait: number): Promise<boolean> {
40
50
  const label = target.instance === undefined ? target.system : instanceLabel({ system: target.system, instance: target.instance });
@@ -48,6 +58,46 @@ export async function waitForSystem(io: CliIo, hub: HubSession, target: { system
48
58
  }
49
59
  }
50
60
 
61
+ /** One install: where from, and what goes with it. */
62
+ interface Install {
63
+ /** A zip, a folder or an npm spec, resolved. */
64
+ readonly path: string;
65
+ readonly kind: 'zip' | 'folder' | 'npm';
66
+ readonly config?: Json | undefined;
67
+ readonly instance?: InstanceName | undefined;
68
+ readonly data?: string | undefined;
69
+ readonly autoStart: boolean;
70
+ }
71
+
72
+ /** Install one system on the hub; says what it installed. */
73
+ async function installOne(io: CliIo, hub: HubSession, install: Install, spec: string): Promise<{ system: SystemName; instance?: InstanceName }> {
74
+ const { config, instance, autoStart } = install;
75
+ if (install.kind === 'zip') {
76
+ const zip = await uploadFile(io, hub, install.path);
77
+ const data = install.data === undefined ? undefined : await uploadFile(io, hub, resolve(io.cwd, install.data));
78
+ const ref = await hub.api.call('installPackage', {
79
+ zip, autoStart, ...(instance === undefined ? {} : { instance }), ...(config === undefined ? {} : { config }), ...(data === undefined ? {} : { data }),
80
+ });
81
+ io.out.line(`installed ${ref.system}@${ref.instance}`);
82
+ return ref;
83
+ }
84
+ const source: InstallSource = install.kind === 'folder' ? { path: install.path } : npmSpec(spec);
85
+ const installed = { system: (await hub.api.call('installSystem', { source, autoStart, ...(config === undefined ? {} : { config }) })).name };
86
+ io.out.line(`installed ${installed.system}`);
87
+ return installed;
88
+ }
89
+
90
+ /** Wait for a premade system to connect, then put it live; false when it didn't get there. */
91
+ async function connectAndGoLive(io: CliIo, hub: HubSession, installed: { system: SystemName; instance?: InstanceName | undefined }, wait: number): Promise<boolean> {
92
+ if (!await waitForSystem(io, hub, installed, wait)) { return false; }
93
+ // a premade system the admin just asked for by name goes live as they would put it (nothing switched off)
94
+ // (it can say it is connected a moment before its contract reaches the hub, so this waits for that too)
95
+ const unpaired = await goLiveWhenPaired(liveApi(hub.api), [installed.system], wait);
96
+ if (unpaired.length > 0) { io.out.warn(`${installed.system} has not sent its contract yet, so it is not live: put it live under Admin > Systems once it does`); return false; }
97
+ io.out.line(`${installed.system} is live`);
98
+ return true;
99
+ }
100
+
51
101
  export const installCommand = command({
52
102
  path: ['system', 'install'],
53
103
  summary: 'Install a package zip, a folder, a premade system by name or an npm package on a hub, which pairs, configures and starts it.',
@@ -66,7 +116,7 @@ export const installCommand = command({
66
116
  async run({ positionals: [target], values }, io) {
67
117
  const given = resolve(io.cwd, target);
68
118
  const stat = await io.files.stat(given);
69
- // a bare name that is no file or folder here, but names a premade system: that system's folder
119
+ // a bare name that is no file or folder here, but names a premade system: that system's folder or package zip
70
120
  const premade = stat === undefined ? await bundledSystem(io, target) : undefined;
71
121
  const path = premade ?? given;
72
122
  const found = premade === undefined ? stat : await io.files.stat(premade);
@@ -74,34 +124,42 @@ export const installCommand = command({
74
124
  const { instance } = values;
75
125
  const autoStart = !values['no-start'];
76
126
  const isZip = found?.kind === 'file' && path.toLowerCase().endsWith('.zip');
127
+ // a premade package zip is the system itself, so --instance and --data go with it as with any package zip
77
128
  if (!isZip && (instance !== undefined || values.data !== undefined)) { io.out.warn('--instance and --data go with a package zip'); return 1; }
129
+ const kind = isZip ? 'zip' : found?.kind === 'folder' ? 'folder' : 'npm';
78
130
  const hub = await io.hub(values);
79
131
  try {
80
- let installed: { system: SystemName; instance?: InstanceName };
81
- if (isZip) {
82
- const zip = await uploadFile(io, hub, path);
83
- const data = values.data === undefined ? undefined : await uploadFile(io, hub, resolve(io.cwd, values.data));
84
- const ref = await hub.api.call('installPackage', {
85
- zip, autoStart, ...(instance === undefined ? {} : { instance }), ...(config === undefined ? {} : { config }), ...(data === undefined ? {} : { data }),
86
- });
87
- io.out.line(`installed ${ref.system}@${ref.instance}`);
88
- installed = ref;
89
- } else {
90
- const source: InstallSource = found?.kind === 'folder' ? { path } : npmSpec(target);
91
- installed = { system: (await hub.api.call('installSystem', { source, autoStart, ...(config === undefined ? {} : { config }) })).name };
92
- io.out.line(`installed ${installed.system}`);
93
- }
94
- if (!autoStart) { return 0; }
95
132
  const wait = values.wait === undefined ? io.settings.HARNESS_CLI_WAIT : Number(values.wait);
96
- if (!await waitForSystem(io, hub, installed, wait)) { return 1; }
97
- // a premade system the admin just asked for by name goes live as they would put it (nothing switched off)
98
- // (it can say it is connected a moment before its contract reaches the hub, so this waits for that too)
99
- if (premade !== undefined) {
100
- const unpaired = await goLiveWhenPaired(liveApi(hub.api), [installed.system], wait);
101
- if (unpaired.length > 0) { io.out.warn(`${installed.system} has not sent its contract yet, so it is not live: put it live under Admin > Systems once it does`); return 1; }
102
- io.out.line(`${installed.system} is live`);
133
+ const about = premade === undefined ? undefined : PREMADE[target];
134
+ // one that `harness start` runs and the hub already has: a second copy would take over its link
135
+ if (about?.start !== undefined && await isInstalled(hub, target)) {
136
+ io.out.line(`${target} is already on this hub (${CLI_NAME} start runs it), so there is nothing to install`);
137
+ return 0;
138
+ }
139
+ // what goes along with a premade system, when the hub doesn't have it yet (database brings widgets)
140
+ const along: string[] = [];
141
+ for (const name of about?.with ?? []) {
142
+ if (!await isInstalled(hub, name)) { along.push(name); }
103
143
  }
104
- return 0;
144
+ const installed = await installOne(io, hub, { path, kind, config, instance, data: values.data, autoStart }, target);
145
+ const companions: Array<{ system: SystemName }> = [];
146
+ for (const name of along) {
147
+ const where = await bundledSystem(io, name);
148
+ if (where === undefined) { io.out.warn(`${name} goes with ${target}, but this harness doesn't carry it`); continue; }
149
+ companions.push(await installOne(io, hub, { path: where, kind: where.toLowerCase().endsWith('.zip') ? 'zip' : 'folder', autoStart }, name));
150
+ }
151
+ if (about?.note !== undefined && (about.with ?? []).length === 0) {
152
+ // a system that is most use beside another (widgets beside database) says so when that one isn't here
153
+ const needs = Object.entries(PREMADE).filter(([, other]) => other.with?.includes(target) === true).map(([name]) => name);
154
+ const missing = [];
155
+ for (const name of needs) { if (!await isInstalled(hub, name)) { missing.push(name); } }
156
+ if (missing.length > 0) { io.out.line(about.note.replaceAll('harness system', `${CLI_NAME} system`)); }
157
+ }
158
+ if (!autoStart) { return 0; }
159
+ if (premade === undefined) { return await waitForSystem(io, hub, installed, wait) ? 0 : 1; }
160
+ let ok = await connectAndGoLive(io, hub, installed, wait);
161
+ for (const companion of companions) { ok = await connectAndGoLive(io, hub, companion, wait) && ok; }
162
+ return ok ? 0 : 1;
105
163
  } finally {
106
164
  hub.close();
107
165
  }
@@ -8,5 +8,6 @@ export { NodeFiles, type CliFiles, type FileStat } from './files.ts';
8
8
  export { cliEnv, cliSettings, connectHub, hubTarget, secretOption, withSavedAdmin, ENV_FILE_URL_REFUSED, type CliEnv, type CliSettings, type HubSession, type SecretFlag, type HubTarget } from './hub.ts';
9
9
  export { nodeIo } from './io.ts';
10
10
  export { goLiveIfInstalled, goLiveWhenPaired, liveApi, type GoLiveOutcome, type LiveApi } from './live.ts';
11
- export { ADMIN_FILE, AdminFile, BUNDLED_SYSTEMS_DIR, CLI_NAME, HARNESS_ROOT, START_SCRIPT, dataFolder, isStartScript, readAdminFile, sameLocalHub, type StartOptions, type StartScript } from './local.ts';
12
- export { bundledSystem, bundledSystems, STARTED_BY_DEFAULT, type BundledSystem } from './commands/available.ts';
11
+ export { ADMIN_FILE, AdminFile, BUNDLED_SYSTEMS_DIR, CLI_NAME, HARNESS_ROOT, PREMADE_DIR, START_SCRIPT, dataFolder, isStartScript, readAdminFile, sameLocalHub, type StartOptions, type StartScript } from './local.ts';
12
+ export { bundledSystem, bundledSystems, type BundledSystem } from './commands/available.ts';
13
+ export { PREMADE, componentOf, packagedSystems, startComponents, startedWhen, systemOfComponent, type Premade } from './premade.ts';
@@ -29,6 +29,12 @@ export const CLI_NAME: string = (() => {
29
29
  /** The premade systems this copy of the harness carries. */
30
30
  export const BUNDLED_SYSTEMS_DIR = join(HARNESS_ROOT, 'systems');
31
31
 
32
+ /**
33
+ * The heavy premade systems as package zips (`premade/<name>.zip`), in the published package only: `harness system
34
+ * install <name>` installs one and the hub fetches the npm packages it left out into its own folder (`premade.ts`).
35
+ */
36
+ export const PREMADE_DIR = join(HARNESS_ROOT, 'premade');
37
+
32
38
  /** Folders in `systems/` that are not systems to install: the template `harness system new` copies. */
33
39
  export const NOT_INSTALLABLE = new Set(['template']);
34
40
 
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The premade systems, in one place: which ones `harness start` runs, which ones ship ready to run in the base package
3
+ * and which ones ship as package zips that pull their own dependencies when installed, and which ones come along with
4
+ * another. `harness system available`, `harness system install`, `scripts/start.ts` and the release pack
5
+ * (`scripts/release/pack.ts`) all read this table, so changing the default set is one edit here.
6
+ *
7
+ * - **Lightweight** systems (their third-party dependencies are ones the hub already has, or a few kB more) ship as
8
+ * their source folder in the base package, so they run with no install step. The `start` ones run with every
9
+ * `harness start`; the others install from that folder (`harness system install schedule`).
10
+ * - **Heavy** systems (`package: true`) are left out of the base package and its dependencies. The release packs each
11
+ * with `harness system pack` into `premade/<name>.zip` (its server bundled, the npm packages named in its
12
+ * `system.json` `server.external` left out), and `harness system install <name>` installs that zip: the hub
13
+ * `npm install`s those externals into the system's own folder, so puppeteer's Chrome or the Claude Agent SDK lands
14
+ * only on a machine that asked for that system. In the repository the folder is there and is used instead.
15
+ * - `with`: systems that are installed alongside it when missing (database brings widgets: widgets draws charts and
16
+ * tables from database queries).
17
+ */
18
+
19
+ /** How one premade system ships and starts. */
20
+ export interface Premade {
21
+ /** When `harness start` runs it: `'always'`, or the settings it needs (it runs once they are all set). */
22
+ readonly start?: 'always' | { readonly when: readonly string[] };
23
+ /** The stack's process name, when it differs from the system's (`calendar` for google-calendar). */
24
+ readonly component?: string;
25
+ /** Shipped as a package zip whose npm dependencies are installed with it, not in the base package. */
26
+ readonly package?: true;
27
+ /** Installed alongside it when not installed yet. */
28
+ readonly with?: readonly string[];
29
+ /** What a person installing it alone should know (shown by `harness system install`). */
30
+ readonly note?: string;
31
+ }
32
+
33
+ /** Every premade system by folder name (the template `harness system new` copies is not one). */
34
+ export const PREMADE: Readonly<Record<string, Premade>> = {
35
+ fs: { start: 'always' },
36
+ input: { start: 'always' },
37
+ code: { start: 'always' },
38
+ schedule: { start: 'always' },
39
+ api: { start: 'always' },
40
+ 'google-calendar': { start: { when: ['GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET'] }, component: 'calendar' },
41
+ embedder: { start: { when: ['HARNESS_EMBEDDER_URL'] } },
42
+ ollama: {},
43
+ mcp: {},
44
+ widgets: { note: 'widgets draws charts and tables from database queries: install database too (harness system install database --config <file.json>)' },
45
+ // @aeye/query and the Postgres and SQL Server drivers (bundled into its zip), and better-sqlite3 built for the machine
46
+ database: { package: true, with: ['widgets'] },
47
+ // puppeteer and the Chrome it downloads
48
+ web: { package: true, component: 'web-system' },
49
+ // the Claude Agent SDK and the Claude Code it carries
50
+ claude: { package: true },
51
+ };
52
+
53
+ /** The premade systems shipped as package zips (left out of the base package). */
54
+ export function packagedSystems(): string[] {
55
+ return Object.entries(PREMADE).filter(([, premade]) => premade.package === true).map(([name]) => name);
56
+ }
57
+
58
+ /** The stack process a premade system runs as (`calendar`, `web-system`, else its own name). */
59
+ export function componentOf(name: string): string {
60
+ return PREMADE[name]?.component ?? name;
61
+ }
62
+
63
+ /** The premade system a stack process name means (`calendar` is google-calendar), or the name itself. */
64
+ export function systemOfComponent(component: string): string {
65
+ return Object.entries(PREMADE).find(([, premade]) => premade.component === component)?.[0] ?? component;
66
+ }
67
+
68
+ /** The stack processes `harness start` runs, given the environment: the hub and the systems whose settings are set. */
69
+ export function startComponents(environment: Readonly<Record<string, string | undefined>>): string[] {
70
+ const started = Object.entries(PREMADE).filter(([, premade]) => premade.start === 'always'
71
+ || (premade.start !== undefined && premade.start.when.every((name) => (environment[name] ?? '') !== '')));
72
+ return ['hub', ...started.map(([name]) => componentOf(name))];
73
+ }
74
+
75
+ /** When `harness start` runs a premade system, in words; undefined when it is installed on demand. */
76
+ export function startedWhen(name: string): string | undefined {
77
+ const start = PREMADE[name]?.start;
78
+ if (start === undefined) { return undefined; }
79
+ return start === 'always' ? 'always' : `when ${start.when.join(' and ')} ${start.when.length === 1 ? 'is' : 'are'} set`;
80
+ }
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "name": "@harness/core",
13
13
  "private": true,
14
- "version": "0.1.0",
14
+ "version": "0.2.0",
15
15
  "license": "Apache-2.0",
16
16
  "type": "module",
17
17
  "description": "Wire contracts: zod schemas and ayepi specs for the system link (both directions), the web API and events. Every record and wire type is derived from them.",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "name": "@harness/hub",
43
43
  "private": true,
44
- "version": "0.1.0",
44
+ "version": "0.2.0",
45
45
  "license": "Apache-2.0",
46
46
  "type": "module",
47
47
  "description": "The hub: store, catalog, system links, execution, chat, index and the web API.",
@@ -4,7 +4,7 @@
4
4
  * (`SystemPackageManifest`, the one source of a system's name, version and entries).
5
5
  */
6
6
  import { execFile } from 'node:child_process';
7
- import { readFile } from 'node:fs/promises';
7
+ import { readFile, writeFile } from 'node:fs/promises';
8
8
  import { join, resolve } from 'node:path';
9
9
  import { promisify } from 'node:util';
10
10
  import { LINK_PROTOCOL, PACKAGE_MANIFEST_FILE, type InstallSource, type InstalledSystem, type SystemPackageManifest } from '@harness/core';
@@ -84,6 +84,11 @@ export class NodeInstaller implements Installer {
84
84
  const entries = unzip(await this.#zips.bytes(hash), this.#maxBytes);
85
85
  const checked = readPackage(entries);
86
86
  await writeTree(entries, dir);
87
+ // a built server is an ES module (`server/main.js`): say so, or Node under the tsx loader reads it as CommonJS
88
+ // when the data folder has no `"type": "module"` package.json above it (only the repository's has one)
89
+ if (!entries.some((entry) => entry.path === 'package.json')) {
90
+ await writeFile(join(dir, 'package.json'), `${JSON.stringify({ private: true, type: 'module' }, null, 2)}\n`);
91
+ }
87
92
  const externals = Object.entries(checked.manifest.server.external).map(([name, range]) => `${name}@${range}`);
88
93
  if (externals.length > 0) {
89
94
  await run(this.#npm, ['install', '--prefix', dir, '--omit=dev', '--no-save', '--no-package-lock', ...externals], { shell: process.platform === 'win32' });
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "name": "@harness/sdk",
21
21
  "private": true,
22
- "version": "0.1.0",
22
+ "version": "0.2.0",
23
23
  "license": "Apache-2.0",
24
24
  "type": "module",
25
25
  "description": "The system author SDK: contracts (system, fn, type, ...), the serve runtime and client renderers.",