@agentage/extension 0.16.0 → 0.18.1

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 (147) hide show
  1. package/dist/api/download.d.ts +14 -0
  2. package/dist/api/download.js +10 -0
  3. package/dist/api/files-registry.d.ts +17 -0
  4. package/dist/api/files-registry.js +10 -0
  5. package/dist/api/files.d.ts +8 -0
  6. package/dist/api/files.js +82 -0
  7. package/dist/api/openapi-doc.js +21 -12
  8. package/dist/api/routes.d.ts +10 -1
  9. package/dist/api/routes.js +15 -2
  10. package/dist/auth/token-check.d.ts +1 -1
  11. package/dist/auth/verify-token.js +9 -9
  12. package/dist/context/test-context.d.ts +5 -1
  13. package/dist/context/test-context.js +2 -1
  14. package/dist/host/daemon/app-files.d.ts +13 -0
  15. package/dist/host/daemon/app-files.js +51 -0
  16. package/dist/host/daemon/app-header.d.ts +3 -0
  17. package/dist/host/daemon/app-header.js +12 -0
  18. package/dist/host/daemon/app-reload.d.ts +10 -0
  19. package/dist/host/daemon/app-reload.js +18 -0
  20. package/dist/host/daemon/child.d.ts +1 -0
  21. package/dist/host/daemon/child.js +7 -4
  22. package/dist/host/daemon/cli-user-watch.d.ts +8 -0
  23. package/dist/host/daemon/cli-user-watch.js +43 -0
  24. package/dist/host/daemon/cli-user.d.ts +2 -0
  25. package/dist/host/daemon/cli-user.js +42 -0
  26. package/dist/host/daemon/daemon.d.ts +1 -0
  27. package/dist/host/daemon/daemon.js +13 -1
  28. package/dist/host/daemon/health-routes.d.ts +2 -0
  29. package/dist/host/daemon/health-routes.js +29 -15
  30. package/dist/host/daemon/limits.d.ts +1 -0
  31. package/dist/host/daemon/limits.js +2 -0
  32. package/dist/host/daemon/routes.js +25 -7
  33. package/dist/host/daemon/seal.d.ts +6 -2
  34. package/dist/host/daemon/seal.js +9 -2
  35. package/dist/host/daemon/shell-events.d.ts +9 -0
  36. package/dist/host/daemon/shell-events.js +36 -0
  37. package/dist/host/daemon/shell-routes.d.ts +28 -0
  38. package/dist/host/daemon/shell-routes.js +63 -0
  39. package/dist/host/daemon/supervisor.d.ts +2 -0
  40. package/dist/host/daemon/supervisor.js +2 -1
  41. package/dist/host/data-lock.js +5 -5
  42. package/dist/host/host-env.js +14 -2
  43. package/dist/host/host-extension.js +4 -3
  44. package/dist/host/host-git-store.d.ts +10 -0
  45. package/dist/host/host-git-store.js +36 -0
  46. package/dist/host/host-migrations.d.ts +1 -1
  47. package/dist/host/host-migrations.js +2 -2
  48. package/dist/host/host-parts.d.ts +2 -2
  49. package/dist/host/host-parts.js +1 -1
  50. package/dist/host/host-url-store.d.ts +4 -2
  51. package/dist/host/host-url-store.js +18 -15
  52. package/dist/host/open-store.d.ts +6 -0
  53. package/dist/host/open-store.js +6 -0
  54. package/dist/index.d.ts +3 -1
  55. package/dist/index.js +3 -1
  56. package/dist/manifest/manifest.schema.d.ts +13 -0
  57. package/dist/manifest/manifest.schema.js +16 -2
  58. package/dist/manifest/parts.d.ts +7 -0
  59. package/dist/manifest/parts.js +5 -0
  60. package/dist/manifest/primitives.schema.js +3 -3
  61. package/dist/mcp/connector.d.ts +4 -0
  62. package/dist/mcp/connector.js +11 -0
  63. package/dist/mcp/mcp-app.d.ts +4 -1
  64. package/dist/mcp/mcp-app.js +28 -18
  65. package/dist/mcp/server.d.ts +6 -3
  66. package/dist/mcp/server.js +70 -18
  67. package/dist/mcp/tools.d.ts +40 -4
  68. package/dist/mcp/tools.js +34 -12
  69. package/dist/runtime/part-mounts.js +12 -6
  70. package/dist/runtime/run-part.js +22 -6
  71. package/dist/server/api-routes.d.ts +5 -2
  72. package/dist/server/api-routes.js +41 -14
  73. package/dist/server/app.d.ts +3 -0
  74. package/dist/server/app.js +11 -1
  75. package/dist/server/send-download.d.ts +3 -0
  76. package/dist/server/send-download.js +29 -0
  77. package/dist/shell/dist/index.html +46 -0
  78. package/dist/shell/dist/shell.css +2 -0
  79. package/dist/shell/dist/shell.js +68 -0
  80. package/dist/shell/dist/vendor/app.js +1 -0
  81. package/dist/shell/dist/vendor/chunk-AOJ3DQEL.js +14 -0
  82. package/dist/shell/dist/vendor/chunk-LW5HXGAJ.js +14 -0
  83. package/dist/shell/dist/vendor/chunk-PQJPUKWH.js +14 -0
  84. package/dist/shell/dist/vendor/chunk-SQE76S5B.js +1 -0
  85. package/dist/shell/dist/vendor/jsx-runtime.js +1 -0
  86. package/dist/shell/dist/vendor/react-dom-client.js +33 -0
  87. package/dist/shell/dist/vendor/react-dom.js +1 -0
  88. package/dist/shell/dist/vendor/react.js +1 -0
  89. package/dist/shell/package.json +5 -0
  90. package/dist/store/git-env.d.ts +11 -0
  91. package/dist/store/git-env.js +44 -0
  92. package/dist/store/store-url.d.ts +1 -1
  93. package/dist/store/store-url.js +2 -0
  94. package/dist/store/store.types.d.ts +3 -0
  95. package/dist/store/store.types.js +1 -1
  96. package/dist/testing/test-server.js +11 -12
  97. package/dist/tool/app-build.d.ts +13 -0
  98. package/dist/tool/app-build.js +126 -0
  99. package/dist/tool/app-load.d.ts +4 -0
  100. package/dist/tool/app-load.js +34 -0
  101. package/dist/tool/build.js +5 -2
  102. package/dist/tool/check.js +4 -2
  103. package/dist/tool/container-recipe.d.ts +9 -2
  104. package/dist/tool/container-recipe.js +14 -9
  105. package/dist/tool/container-stage.js +1 -1
  106. package/dist/tool/index.d.ts +1 -0
  107. package/dist/tool/index.js +1 -0
  108. package/dist/tool/main.d.ts +2 -0
  109. package/dist/tool/main.js +8 -1
  110. package/dist/tool/recipe.d.ts +1 -1
  111. package/dist/tool/recipe.js +16 -6
  112. package/dist/tool/record-extras.js +4 -3
  113. package/dist/tool/rules/folders.js +1 -1
  114. package/dist/tool/rules/sealing.js +4 -0
  115. package/dist/tool/rules/store.js +0 -3
  116. package/dist/tool/rules/surface.js +4 -1
  117. package/dist/tool/stage.js +2 -2
  118. package/dist/tool/up/compose.d.ts +4 -0
  119. package/dist/tool/up/compose.js +41 -3
  120. package/dist/tool/up/gateway.js +16 -3
  121. package/dist/tool/up/secrets.d.ts +1 -0
  122. package/dist/tool/up/secrets.js +13 -1
  123. package/dist/tool/up/up.js +8 -5
  124. package/dist/vendor/app/api.d.ts +9 -0
  125. package/dist/vendor/app/api.js +63 -0
  126. package/dist/vendor/app/app.types.d.ts +65 -0
  127. package/dist/vendor/app/app.types.js +1 -0
  128. package/dist/vendor/app/boundary.d.ts +15 -0
  129. package/dist/vendor/app/boundary.js +17 -0
  130. package/dist/vendor/app/context.d.ts +5 -0
  131. package/dist/vendor/app/context.js +22 -0
  132. package/dist/vendor/app/index.d.ts +7 -0
  133. package/dist/vendor/app/index.js +6 -0
  134. package/dist/vendor/app/region.d.ts +6 -0
  135. package/dist/vendor/app/region.js +14 -0
  136. package/dist/vendor/app/split.d.ts +20 -0
  137. package/dist/vendor/app/split.js +38 -0
  138. package/dist/vendor/app/state-store.d.ts +3 -0
  139. package/dist/vendor/app/state-store.js +35 -0
  140. package/dist/vendor/app/test-host.d.ts +29 -0
  141. package/dist/vendor/app/test-host.js +66 -0
  142. package/dist/vendor/app/theme.css +32 -0
  143. package/package.json +35 -2
  144. package/schemas/extension-discovery.schema.json +1 -1
  145. package/schemas/extension-package.schema.json +28 -1
  146. package/schemas/extension-record.schema.json +1 -1
  147. package/schemas/health.schema.json +1 -1
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@agentage/shell-dashboard",
3
+ "version": "0.1.0",
4
+ "private": true
5
+ }
@@ -0,0 +1,11 @@
1
+ export interface GitAccess {
2
+ readonly remote?: string;
3
+ readonly cwd: string;
4
+ readonly env: Readonly<Record<string, string>>;
5
+ }
6
+ export declare const splitCredential: (url: string) => {
7
+ remote: string;
8
+ header?: string;
9
+ };
10
+ export declare const gitEnvOf: (root: string, remote?: string, header?: string) => Record<string, string>;
11
+ export declare const gitAccessOf: (root: string, url?: string) => GitAccess;
@@ -0,0 +1,44 @@
1
+ import { inspect } from 'node:util';
2
+ // The URL of the estate file holds user:password; git gets it as a header, never in a URL or argv.
3
+ export const splitCredential = (url) => {
4
+ const parsed = new URL(url);
5
+ const user = decodeURIComponent(parsed.username);
6
+ const password = decodeURIComponent(parsed.password);
7
+ parsed.username = '';
8
+ parsed.password = '';
9
+ if (!user && !password)
10
+ return { remote: parsed.href };
11
+ const basic = Buffer.from(`${user}:${password}`).toString('base64');
12
+ return { remote: parsed.href, header: `Authorization: Basic ${basic}` };
13
+ };
14
+ // No host or user config, no hooks, no ext:: transport, no prompt; only PATH from the parent.
15
+ const configOf = (remote, header) => [
16
+ ['core.hooksPath', '/dev/null'],
17
+ ...(remote && header ? [[`http.${remote}.extraHeader`, header]] : []),
18
+ ];
19
+ export const gitEnvOf = (root, remote, header) => {
20
+ const config = configOf(remote, header);
21
+ const env = {
22
+ PATH: process.env['PATH'] ?? '/usr/bin:/bin',
23
+ HOME: root,
24
+ GIT_CONFIG_NOSYSTEM: '1',
25
+ GIT_CONFIG_GLOBAL: '/dev/null',
26
+ GIT_TERMINAL_PROMPT: '0',
27
+ GIT_ALLOW_PROTOCOL: 'file:http:https',
28
+ GIT_CONFIG_COUNT: String(config.length),
29
+ };
30
+ config.forEach(([key, value], i) => {
31
+ env[`GIT_CONFIG_KEY_${i}`] = key;
32
+ env[`GIT_CONFIG_VALUE_${i}`] = value;
33
+ });
34
+ return env;
35
+ };
36
+ // A log line or a JSON dump of ctx.store shows no env, so it shows no credential.
37
+ export const gitAccessOf = (root, url) => {
38
+ const { remote, header } = url ? splitCredential(url) : { remote: undefined, header: undefined };
39
+ const shown = { ...(remote && { remote }), cwd: root, env: '[redacted]' };
40
+ return Object.defineProperties({ ...(remote && { remote }), cwd: root, env: gitEnvOf(root, remote, header) }, {
41
+ toJSON: { value: () => shown },
42
+ [inspect.custom]: { value: () => shown },
43
+ });
44
+ };
@@ -1,4 +1,4 @@
1
1
  export declare const STORE_URL_FILE_ENV = "AGENTAGE_STORE_URL_FILE";
2
2
  export type UrlStoreKind = 'postgres' | 'clickhouse';
3
3
  export declare const isUrlStoreKind: (kind: string | undefined) => kind is UrlStoreKind;
4
- export declare const readStoreUrl: (file: string, kind: UrlStoreKind, read?: (at: string) => Promise<string>) => Promise<string>;
4
+ export declare const readStoreUrl: (file: string, kind: UrlStoreKind | "git", read?: (at: string) => Promise<string>) => Promise<string>;
@@ -1,9 +1,11 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { messageOf } from '../log/log.js';
3
3
  export const STORE_URL_FILE_ENV = 'AGENTAGE_STORE_URL_FILE';
4
+ // git reads its URL too, as the remote of its repos (the host opens the repos in dataDir).
4
5
  const SCHEMES = {
5
6
  postgres: { protocol: /^postgres(ql)?:$/, form: 'postgres://' },
6
7
  clickhouse: { protocol: /^https?:$/, form: 'http:// or https://' },
8
+ git: { protocol: /^https?:$/, form: 'http:// or https://' },
7
9
  };
8
10
  export const isUrlStoreKind = (kind) => kind === 'postgres' || kind === 'clickhouse';
9
11
  const refused = (file, why) => new Error(`${STORE_URL_FILE_ENV} ${file}: ${why}`);
@@ -1,7 +1,10 @@
1
+ import { type GitAccess } from './git-env.js';
1
2
  export type Row = Record<string, unknown>;
2
3
  export interface QueryResult<R extends Row = Row> {
3
4
  rows: R[];
4
5
  }
5
6
  export interface Store {
6
7
  query<R extends Row = Row>(text: string, params?: unknown[]): Promise<QueryResult<R>>;
8
+ readonly gitRoot?: string;
9
+ readonly git?: GitAccess;
7
10
  }
@@ -1 +1 @@
1
- export {};
1
+ import {} from './git-env.js';
@@ -6,11 +6,11 @@ import { callerOf } from '../auth/token-check.js';
6
6
  import {} from '../context/context.js';
7
7
  import { createTestContext } from '../context/test-context.js';
8
8
  import {} from '../manifest/manifest.schema.js';
9
- import { createMcpApp } from '../mcp/mcp-app.js';
9
+ import { mountWithConnector } from '../mcp/connector.js';
10
10
  import { callTool } from '../mcp/snapshot.js';
11
11
  import { createToolRegistry, prefixed } from '../mcp/tools.js';
12
12
  import { mountApi } from '../server/api-routes.js';
13
- import { createApiApp } from '../server/app.js';
13
+ import { createApiApp, createPartApp } from '../server/app.js';
14
14
  import {} from '../server/part.types.js';
15
15
  import { listen } from '../server/serve.js';
16
16
  import { KIT_VERSION } from '../tool/kit-version.js';
@@ -42,22 +42,21 @@ export const startTestServer = async (options) => {
42
42
  tokenCheck: callerCheck(ctx.extension.id, options.caller ?? null),
43
43
  openapi: generatedOpenapi(pkg, mounted.routes),
44
44
  };
45
- const base = { pkg, build: TEST_BUILD, log: ctx.log, wellKnown: mounted.documents };
45
+ const { documents: wellKnown, files } = mounted;
46
+ const base = { pkg, build: TEST_BUILD, log: ctx.log, wellKnown, files };
46
47
  return startOn(createApiApp({ ...base, router: mounted.router, routes: mounted.routes, ...guard }));
47
48
  };
48
- // Runs an mcp part's create(ctx) inside the kit's real /mcp app: tools named {id}__{name}.
49
+ // Runs an mcp part's create(ctx) inside the kit's real /mcp app: tools named {id}__{name}; connector tools at /connector.
49
50
  export const startTestMcp = async (options) => {
50
51
  const ctx = options.ctx ?? createTestContext();
51
52
  const registry = createToolRegistry();
52
- await options.create({ ...ctx, tool: registry.tool });
53
+ const { tool, instructions, connector } = registry;
54
+ await options.create({ ...ctx, tool, instructions, connector });
53
55
  const pkg = testPackage(ctx, { mcp: true });
54
- const app = createMcpApp({
55
- pkg,
56
- build: TEST_BUILD,
57
- log: ctx.log,
58
- tools: registry.tools,
59
- listing: 'open',
60
- });
56
+ const base = { pkg, build: TEST_BUILD, log: ctx.log, tools: registry.tools };
57
+ const mcp = { ...base, listing: 'open', ...registry.served };
58
+ const mount = (app) => mountWithConnector(app, mcp, registry.connectors);
59
+ const app = createPartApp({ ...mcp, part: 'mcp', mount });
61
60
  const server = await startOn(app);
62
61
  const call = (name, args = {}) => callTool(`${server.url}/mcp`, prefixed(ctx.extension.id, name), args);
63
62
  return { ...server, call };
@@ -0,0 +1,13 @@
1
+ import type * as Esbuild from 'esbuild';
2
+ export declare const APP_EXTERNALS: readonly ["react", "react/jsx-runtime", "react-dom", "react-dom/client", "@agentage/extension/app"];
3
+ export interface AppFiles {
4
+ entry: string;
5
+ css: string;
6
+ }
7
+ export interface AppBuilder {
8
+ rebuild(): Promise<AppFiles>;
9
+ dispose(): Promise<void>;
10
+ }
11
+ export declare const dsSources: (dir: string, metafile?: Esbuild.Metafile) => string[];
12
+ export declare const appBuilder: (at: string) => Promise<AppBuilder>;
13
+ export declare const buildApp: (dir: string) => Promise<AppFiles>;
@@ -0,0 +1,126 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { APP_DIR, APP_META_FILE } from '../manifest/parts.js';
5
+ import { exists } from './stage.js';
6
+ import { loadFrom, packageDir, requireBuildDeps, resolveFrom } from './app-load.js';
7
+ // K4: one React and one @agentage/extension/app for the shell and every app, given by the import map.
8
+ export const APP_EXTERNALS = [
9
+ 'react',
10
+ 'react/jsx-runtime',
11
+ 'react-dom',
12
+ 'react-dom/client',
13
+ '@agentage/extension/app',
14
+ ];
15
+ const SOURCES = ['index.tsx', 'index.ts', 'index.jsx', 'index.js'];
16
+ const sourceOf = async (dir) => {
17
+ for (const name of SOURCES) {
18
+ const file = join(dir, 'src', 'app', name);
19
+ if (await exists(file))
20
+ return file;
21
+ }
22
+ throw new Error('src/app/index.tsx not found: the app part is one root component there');
23
+ };
24
+ const esbuildOptions = (dir, entry) => ({
25
+ entryPoints: [entry],
26
+ bundle: true,
27
+ format: 'esm',
28
+ jsx: 'automatic',
29
+ platform: 'browser',
30
+ target: 'es2022',
31
+ minify: true,
32
+ legalComments: 'none',
33
+ logLevel: 'silent',
34
+ absWorkingDir: dir,
35
+ external: [...APP_EXTERNALS],
36
+ define: { 'process.env.NODE_ENV': '"production"' },
37
+ write: false,
38
+ metafile: true,
39
+ outfile: join(dir, APP_DIR, 'app.js'),
40
+ });
41
+ const DS = /(^|\/)node_modules\/@agentage\/design-system\//;
42
+ // The design-system files the app bundles: their classes are scanned too, or a DS Button has no style.
43
+ export const dsSources = (dir, metafile) => Object.keys(metafile?.inputs ?? {})
44
+ .filter((file) => DS.test(file))
45
+ .map((file) => resolve(dir, file));
46
+ // The @theme blocks of the design-system tokens (the file also has :root rules), as reference only.
47
+ const dsTheme = async (dir) => {
48
+ const file = resolveFrom(dir, '@agentage/design-system/styles/tokens.css');
49
+ if (!file)
50
+ return [];
51
+ const blocks = (await readFile(file, 'utf8')).match(/@theme\s*\{[^{}]*\}/g) ?? [];
52
+ return blocks.map((b) => b.replace(/^@theme/, '@theme reference'));
53
+ };
54
+ // Utilities only, no preflight and no theme variables: the shell owns both.
55
+ // Token names only (reference): utilities like bg-primary exist; the shell gives the values.
56
+ const cssInput = async (dir, extra) => {
57
+ const tw = packageDir(dir, 'tailwindcss');
58
+ const tokens = resolveFrom(dir, '@agentage/extension/app/theme.css');
59
+ return [
60
+ '@layer theme, utilities;',
61
+ `@import "${join(tw, 'theme.css')}" layer(theme) theme(reference inline);`,
62
+ ...(await dsTheme(dir)),
63
+ ...(tokens ? [`@import "${tokens}" layer(theme) theme(reference);`] : []),
64
+ `@import "${join(tw, 'utilities.css')}" layer(utilities) source(none);`,
65
+ `@source "${join(dir, 'src', 'app')}";`,
66
+ ...extra.map((file) => `@source "${file}";`),
67
+ ].join('\n');
68
+ };
69
+ const compileCss = async (dir, extra) => {
70
+ const postcss = await loadFrom(dir, 'postcss');
71
+ const tailwind = await loadFrom(dir, '@tailwindcss/postcss');
72
+ const plugin = tailwind({ base: dir, optimize: { minify: true } });
73
+ const from = join(dir, 'src', 'app', 'app.css');
74
+ return (await postcss([plugin]).process(await cssInput(dir, extra), { from })).css;
75
+ };
76
+ const hashed = (code, ext) => `app-${createHash('sha256').update(code).digest('hex').slice(0, 10)}.${ext}`;
77
+ // Written then renamed: a reader sees the old file or the new one, never half of one.
78
+ const writeAtomic = async (file, text) => {
79
+ await writeFile(`${file}.tmp`, text);
80
+ await rename(`${file}.tmp`, file);
81
+ };
82
+ const previous = async (out) => {
83
+ const text = await readFile(join(out, APP_META_FILE), 'utf8').catch(() => '{}');
84
+ const meta = JSON.parse(text);
85
+ return [meta.entry, meta.css].filter((name) => typeof name === 'string');
86
+ };
87
+ // The current and the previous build stay: an open page may still import the previous one.
88
+ const prune = async (out, keep) => {
89
+ const old = (await readdir(out)).filter((name) => /^app-.+\.(js|css)$/.test(name));
90
+ await Promise.all(old.filter((n) => !keep.includes(n)).map((n) => rm(join(out, n))));
91
+ };
92
+ const writeApp = async (dir, code, css) => {
93
+ const out = join(dir, APP_DIR);
94
+ await mkdir(out, { recursive: true });
95
+ const files = { entry: hashed(code, 'js'), css: hashed(css, 'css') };
96
+ const kept = await previous(out);
97
+ await writeFile(join(out, files.entry), code);
98
+ await writeFile(join(out, files.css), css);
99
+ await writeAtomic(join(out, 'index.js'), `export { default } from './${files.entry}';\n`);
100
+ await writeAtomic(join(out, APP_META_FILE), `${JSON.stringify(files)}\n`);
101
+ await prune(out, [...kept, files.entry, files.css]);
102
+ return files;
103
+ };
104
+ // A warm esbuild context: `up` calls rebuild() on each save; dispose() when it stops.
105
+ export const appBuilder = async (at) => {
106
+ const dir = resolve(at);
107
+ requireBuildDeps(dir);
108
+ const esbuild = await loadFrom(dir, 'esbuild');
109
+ const ctx = await esbuild.context(esbuildOptions(dir, await sourceOf(dir)));
110
+ const rebuild = async () => {
111
+ const result = await ctx.rebuild();
112
+ const code = result.outputFiles?.[0]?.contents ?? new Uint8Array();
113
+ return writeApp(dir, code, await compileCss(dir, dsSources(dir, result.metafile)));
114
+ };
115
+ return { rebuild, dispose: () => ctx.dispose() };
116
+ };
117
+ // dist/app: app-<hash>.js and .css (immutable), index.js and app.json (no-cache) naming them.
118
+ export const buildApp = async (dir) => {
119
+ const builder = await appBuilder(dir);
120
+ try {
121
+ return await builder.rebuild();
122
+ }
123
+ finally {
124
+ await builder.dispose();
125
+ }
126
+ };
@@ -0,0 +1,4 @@
1
+ export declare const resolveFrom: (dir: string, name: string) => string | undefined;
2
+ export declare const loadFrom: <T>(dir: string, name: string) => Promise<T>;
3
+ export declare const packageDir: (dir: string, name: string) => string;
4
+ export declare const requireBuildDeps: (dir: string, find?: (dir: string, name: string) => string | undefined) => void;
@@ -0,0 +1,34 @@
1
+ import { createRequire } from 'node:module';
2
+ import { dirname, join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ // The extension's own copy first (its devDependencies), else the one beside the kit (the cli's).
5
+ export const resolveFrom = (dir, name) => {
6
+ for (const base of [join(dir, 'package.json'), import.meta.url]) {
7
+ try {
8
+ return createRequire(base).resolve(name);
9
+ }
10
+ catch {
11
+ // not there: the next base
12
+ }
13
+ }
14
+ return undefined;
15
+ };
16
+ const needed = (dir, name) => {
17
+ const file = resolveFrom(dir, name);
18
+ if (!file)
19
+ throw new Error(`the app part needs ${name}: npm install --save-dev ${name}`);
20
+ return file;
21
+ };
22
+ // A CommonJS module comes back as its default export.
23
+ export const loadFrom = async (dir, name) => {
24
+ const mod = (await import(pathToFileURL(needed(dir, name)).href));
25
+ return mod.default ?? mod;
26
+ };
27
+ export const packageDir = (dir, name) => dirname(needed(dir, `${name}/package.json`));
28
+ const BUILD_DEPS = ['esbuild', 'postcss', '@tailwindcss/postcss', 'tailwindcss'];
29
+ // One clear error, before any work, for the build tools the extension did not install.
30
+ export const requireBuildDeps = (dir, find = resolveFrom) => {
31
+ const missing = BUILD_DEPS.filter((name) => !find(dir, name));
32
+ if (missing.length)
33
+ throw new Error(`the app build needs ${missing.join(', ')}: npm install --save-dev ${missing.join(' ')}`);
34
+ };
@@ -3,11 +3,12 @@ import { join, resolve } from 'node:path';
3
3
  import { recordOf, validateRecord } from '../discovery/discovery.js';
4
4
  import {} from '../discovery/discovery.schema.js';
5
5
  import {} from '../manifest/manifest.schema.js';
6
- import { imageParts } from '../manifest/parts.js';
6
+ import { appOf, imageParts } from '../manifest/parts.js';
7
7
  import {} from '../manifest/primitives.schema.js';
8
8
  import { readManifest } from '../manifest/read-manifest.js';
9
9
  import {} from '../runtime/build-info.js';
10
10
  import { resolveBuildInfo } from './build-info.js';
11
+ import { buildApp } from './app-build.js';
11
12
  import { assertConforms } from './check.js';
12
13
  import { containerParts } from './container-parts.js';
13
14
  import { buildContainer, CONTAINER_RECORD_FILE } from './container.js';
@@ -76,13 +77,15 @@ const partImages = async (base, options, deps) => {
76
77
  const record = await recordFor(base.dir, base.pkg, base.info, images);
77
78
  return { images, recordFile: await writeRecord(base.dir, record) };
78
79
  };
79
- // Validate, compile, check, one image per part (or the one image); --push pushes, writes the record.
80
+ // Validate, compile, the app bundle, check, one image per part (or the one image); --push pushes, writes the record.
80
81
  export const build = async (options = {}, deps = { run: runCommand }) => {
81
82
  const dir = resolve(options.dir ?? '.');
82
83
  const pkg = await readManifest(dir);
83
84
  const parts = options.container ? containerParts(pkg) : undefined;
84
85
  const info = await resolveBuildInfo(dir, options.env ?? process.env, deps.run);
85
86
  await compile(dir, pkg, deps.run);
87
+ if (appOf(pkg))
88
+ await buildApp(dir);
86
89
  const warnings = await assertConforms(dir, { run: deps.run });
87
90
  const base = { dir, pkg, info };
88
91
  const built = parts
@@ -5,7 +5,7 @@ import semver from 'semver';
5
5
  import { checkCli } from '../command/check-cli.js';
6
6
  import { messageOf } from '../log/log.js';
7
7
  import { PackageSchema } from '../manifest/manifest.schema.js';
8
- import { entryOf, normalizeParts } from '../manifest/parts.js';
8
+ import { appOf, entryOf, normalizeParts } from '../manifest/parts.js';
9
9
  import {} from '../manifest/primitives.schema.js';
10
10
  import { formatIssues, readJsonIfExists } from '../manifest/read-manifest.js';
11
11
  import { runCommand } from './exec.js';
@@ -54,6 +54,8 @@ const partProblem = async ({ dir, pkg }, part) => {
54
54
  return `${normalize(entryOf(pkg, part))} not found: the package build must write the cli part there`;
55
55
  return part === 'ui' ? null : exportProblem(dir, pkg, part);
56
56
  };
57
+ const APP_BUILT = 'dist/app/index.js not found: the package build must write the app part (agentage-extension app)';
58
+ const appProblem = async ({ dir, pkg }) => appOf(pkg) && !(await exists(join(dir, 'dist/app/index.js'))) ? [{ problem: APP_BUILT }] : [];
57
59
  // Every part built and exporting only create; cli handlers = commands; exports hold no part code.
58
60
  const entries = {
59
61
  name: 'entries',
@@ -63,7 +65,7 @@ const entries = {
63
65
  const parts = Object.keys(normalizeParts(input.pkg.agentage.parts).code);
64
66
  const found = parts.map((part) => partProblem(input, part).catch(messageOf));
65
67
  const problems = (await Promise.all(found)).flatMap((problem) => problem ? [{ problem }] : []);
66
- return [...problems, ...exportedPartCode(input.pkg)];
68
+ return [...problems, ...(await appProblem(input)), ...exportedPartCode(input.pkg)];
67
69
  },
68
70
  };
69
71
  const MAJORS = { express: '^5', zod: '^4', '@modelcontextprotocol/server': '^2' };
@@ -1,4 +1,11 @@
1
1
  export declare const CONTAINER_PORT = 8080;
2
- export declare const containerRecipe: ({ pglite }: {
2
+ export declare const DATA_VOLUME = "/data";
3
+ export declare const STORE_DIR = "/data/store";
4
+ export declare const GIT_INSTALL = "RUN apk add --no-cache git git-daemon";
5
+ export declare const DATA_VOLUME_LINES: string[];
6
+ interface Stores {
3
7
  pglite?: string;
4
- }) => string;
8
+ git?: boolean;
9
+ }
10
+ export declare const containerRecipe: (stores: Stores) => string;
11
+ export {};
@@ -1,7 +1,13 @@
1
1
  export const CONTAINER_PORT = 8080;
2
2
  // The volume holds the store folder, so its <dir>.lock sibling persists with it.
3
- const DATA_VOLUME = '/data';
4
- const STORE_DIR = `${DATA_VOLUME}/store`;
3
+ export const DATA_VOLUME = '/data';
4
+ export const STORE_DIR = `${DATA_VOLUME}/store`;
5
+ // git-daemon brings git http-backend, which a part serving smart HTTP spawns.
6
+ export const GIT_INSTALL = 'RUN apk add --no-cache git git-daemon';
7
+ export const DATA_VOLUME_LINES = [
8
+ `RUN mkdir -p ${DATA_VOLUME} && chown node:node ${DATA_VOLUME}`,
9
+ `VOLUME ${DATA_VOLUME}`,
10
+ ];
5
11
  const HEALTH_PROBE = `fetch('http://127.0.0.1:'+(process.env.PORT||${CONTAINER_PORT})+'/health')` +
6
12
  '.then((r) => process.exit(r.status === 200 || r.status === 503 ? 0 : 1), () => process.exit(1))';
7
13
  const DEPS = [
@@ -32,19 +38,18 @@ const runnerEnv = (store) => [
32
38
  ' COMMIT_SHA=$COMMIT_SHA \\',
33
39
  ' BUILD_TIME=$BUILD_TIME',
34
40
  ];
35
- const runner = (store) => [
36
- ...runnerEnv(store),
41
+ const runner = ({ pglite, git }) => [
42
+ ...runnerEnv(pglite !== undefined || Boolean(git)),
43
+ ...(git ? [GIT_INSTALL] : []),
37
44
  'WORKDIR /app',
38
45
  'COPY --from=deps /app/node_modules ./node_modules',
39
- ...(store
46
+ ...(pglite !== undefined
40
47
  ? [
41
48
  'COPY --from=pglite /pglite/node_modules/@electric-sql/pglite ./node_modules/@electric-sql/pglite',
42
49
  ]
43
50
  : []),
44
51
  'COPY app/ ./',
45
- ...(store
46
- ? [`RUN mkdir -p ${DATA_VOLUME} && chown node:node ${DATA_VOLUME}`, `VOLUME ${DATA_VOLUME}`]
47
- : []),
52
+ ...(pglite !== undefined || git ? DATA_VOLUME_LINES : []),
48
53
  'USER node',
49
54
  `EXPOSE ${CONTAINER_PORT}`,
50
55
  `HEALTHCHECK --interval=10s --timeout=3s --start-period=15s --retries=3 CMD ["node", "-e", "${HEALTH_PROBE}"]`,
@@ -52,4 +57,4 @@ const runner = (store) => [
52
57
  '',
53
58
  ];
54
59
  // The one image of an extension: the kit host in one process; pglite is set for a postgres store.
55
- export const containerRecipe = ({ pglite }) => [...DEPS, ...(pglite ? pgliteStage(pglite) : []), ...runner(pglite !== undefined)].join('\n');
60
+ export const containerRecipe = (stores) => [...DEPS, ...(stores.pglite ? pgliteStage(stores.pglite) : []), ...runner(stores)].join('\n');
@@ -46,6 +46,6 @@ export const stageContainer = async (dir, pkg, tmpRoot = tmpdir()) => {
46
46
  for (const path of await containerPaths(dir, pkg))
47
47
  await cp(join(dir, path), join(root, 'app', path), { recursive: true, filter });
48
48
  const pglite = hasStore(pkg, 'postgres') ? await pgliteVersion(dir) : undefined;
49
- await writeFile(join(root, 'Dockerfile'), containerRecipe({ pglite }));
49
+ await writeFile(join(root, 'Dockerfile'), containerRecipe({ pglite, git: hasStore(pkg, 'git') }));
50
50
  return root;
51
51
  };
@@ -5,6 +5,7 @@ export { imageParts } from '../manifest/parts.js';
5
5
  export { SERVED_KINDS, STORE_KINDS, type StoreKind } from '../manifest/primitives.schema.js';
6
6
  export { readManifest, validateManifest } from '../manifest/read-manifest.js';
7
7
  export { canonical, mcpSnapshot, PROTOCOL_VERSIONS, type McpSnapshot, type ProtocolVersion, } from '../mcp/snapshot.js';
8
+ export { APP_EXTERNALS, appBuilder, buildApp, type AppBuilder, type AppFiles, } from './app-build.js';
8
9
  export { build, type BuildDeps, type BuildOptions, type BuildResult, type BuiltImage, } from './build.js';
9
10
  export { type BuiltContainer } from './container.js';
10
11
  export { capabilities } from './capabilities.js';
@@ -5,6 +5,7 @@ export { imageParts } from '../manifest/parts.js';
5
5
  export { SERVED_KINDS, STORE_KINDS } from '../manifest/primitives.schema.js';
6
6
  export { readManifest, validateManifest } from '../manifest/read-manifest.js';
7
7
  export { canonical, mcpSnapshot, PROTOCOL_VERSIONS, } from '../mcp/snapshot.js';
8
+ export { APP_EXTERNALS, appBuilder, buildApp, } from './app-build.js';
8
9
  export { build, } from './build.js';
9
10
  export {} from './container.js';
10
11
  export { capabilities } from './capabilities.js';
@@ -1,9 +1,11 @@
1
+ import { type AppFiles } from './app-build.js';
1
2
  import { type BuildOptions, type BuildResult } from './build.js';
2
3
  import { type DownOptions } from './up/down.js';
3
4
  import { type TokenOptions } from './up/token.js';
4
5
  import { type UpOptions } from './up/up.js';
5
6
  export interface MainDeps {
6
7
  build: (options: BuildOptions) => Promise<BuildResult>;
8
+ app: (dir: string) => Promise<AppFiles>;
7
9
  up: (options: UpOptions) => Promise<unknown>;
8
10
  down: (options: DownOptions) => Promise<unknown>;
9
11
  token: (options: TokenOptions) => Promise<string>;
package/dist/tool/main.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { parseArgs } from 'node:util';
2
2
  import { UsageError } from '../command/args.js';
3
3
  import { EXIT_FAILED, EXIT_OK, EXIT_USAGE } from '../command/run-command.js';
4
+ import { buildApp } from './app-build.js';
4
5
  import { build } from './build.js';
5
6
  import { buildLines } from './format.js';
6
7
  import { down } from './up/down.js';
7
8
  import { token } from './up/token.js';
8
9
  import { up } from './up/up.js';
9
- const USAGE = `usage: agentage-extension <build|up|down|token> [options]
10
+ const USAGE = `usage: agentage-extension <build|app|up|down|token> [options]
10
11
 
11
12
  build one image per part from the kit recipe
12
13
  --push push the images and write dist/agentage-extension.json with their digests
@@ -14,12 +15,14 @@ const USAGE = `usage: agentage-extension <build|up|down|token> [options]
14
15
  lists the parts it does not run yet; with --push the record is
15
16
  dist/agentage-container.json
16
17
  --registry image registry and owner (default: ghcr.io/agentage)
18
+ app the app part only: dist/app (index.js, app.json, hashed js and css)
17
19
  up the release images on Docker: store, dev issuer, gateway on localhost:4280
18
20
  down remove what up started; --keep-data keeps the store volume
19
21
  token a dev token: --scope <id>:<verb> [--issuer <url>]
20
22
  --dir the extension package folder (default: the current folder)`;
21
23
  const defaultDeps = {
22
24
  build,
25
+ app: buildApp,
23
26
  up,
24
27
  down,
25
28
  token,
@@ -47,6 +50,10 @@ const COMMANDS = {
47
50
  })))
48
51
  deps.out(line);
49
52
  },
53
+ app: async (v, deps) => {
54
+ const { entry, css } = await deps.app(v.dir ?? '.');
55
+ deps.out(`app dist/app/${entry} dist/app/${css}`);
56
+ },
50
57
  up: async (v, deps) => void (await deps.up({ dir: v.dir, onLine: deps.out })),
51
58
  down: async (v, deps) => void (await deps.down({ dir: v.dir, keepData: v['keep-data'], onLine: deps.out })),
52
59
  token: async (v, deps) => {
@@ -1,2 +1,2 @@
1
1
  import { type ImagePartKind } from '../manifest/primitives.schema.js';
2
- export declare const serverPartRecipe: (part: ImagePartKind) => string;
2
+ export declare const serverPartRecipe: (part: ImagePartKind, git?: boolean) => string;
@@ -1,9 +1,10 @@
1
1
  import {} from '../manifest/primitives.schema.js';
2
+ import { DATA_VOLUME_LINES, GIT_INSTALL, STORE_DIR } from './container-recipe.js';
2
3
  const PART_PORT = 3000;
3
4
  // 503 passes: a restart cannot fix a dependency outage, so only a dead or 404 part is unhealthy.
4
5
  const HEALTH_PROBE = `fetch('http://127.0.0.1:${PART_PORT}/health')` +
5
6
  '.then((r) => process.exit(r.status === 200 || r.status === 503 ? 0 : 1), () => process.exit(1))';
6
- const RECIPE = [
7
+ const BASE = [
7
8
  '# syntax=docker/dockerfile:1',
8
9
  '# Generated by @agentage/extension build. Extension authors never write a Dockerfile.',
9
10
  'FROM node:26-alpine AS deps',
@@ -21,16 +22,25 @@ const RECIPE = [
21
22
  ' COMMIT_SHA=$COMMIT_SHA \\',
22
23
  ' BUILD_TIME=$BUILD_TIME \\',
23
24
  ' AGENTAGE_IMAGE=$IMAGE',
24
- 'WORKDIR /app',
25
- 'COPY --from=deps /app/node_modules ./node_modules',
26
- 'COPY app/ ./',
25
+ ];
26
+ const APP = ['WORKDIR /app', 'COPY --from=deps /app/node_modules ./node_modules', 'COPY app/ ./'];
27
+ const RUN = [
27
28
  'USER node',
28
29
  `EXPOSE ${PART_PORT}`,
29
30
  `HEALTHCHECK --interval=10s --timeout=3s --start-period=15s --retries=3 CMD ["node", "-e", "${HEALTH_PROBE}"]`,
30
31
  ];
32
+ // A git store part: the git binary, its repos on the /data volume (as in the one container).
33
+ const gitLines = (git) => ({
34
+ env: git ? [`ENV AGENTAGE_DATA_DIR=${STORE_DIR}`, GIT_INSTALL] : [],
35
+ volume: git ? DATA_VOLUME_LINES : [],
36
+ });
31
37
  // The one recipe for a Node server part; the staged context holds deps/ (npm ci) and app/ (code).
32
- export const serverPartRecipe = (part) => [
33
- ...RECIPE,
38
+ export const serverPartRecipe = (part, git = false) => [
39
+ ...BASE,
40
+ ...gitLines(git).env,
41
+ ...APP,
42
+ ...gitLines(git).volume,
43
+ ...RUN,
34
44
  `CMD ["node", "node_modules/@agentage/extension/dist/runtime/main.js", "${part}"]`,
35
45
  '',
36
46
  ].join('\n');
@@ -31,14 +31,15 @@ export const recordingContext = (pkg, part) => createContext({
31
31
  });
32
32
  export const registeredTools = async (create, pkg) => {
33
33
  const registry = createToolRegistry();
34
- await create({ ...recordingContext(pkg, 'mcp'), tool: registry.tool });
34
+ const { tool, instructions, connector } = registry;
35
+ await create({ ...recordingContext(pkg, 'mcp'), tool, instructions, connector });
35
36
  return registry.tools;
36
37
  };
37
38
  // What an api part's create(ctx) registers with ctx.route, and what it returns.
38
39
  export const registeredRoutes = async (create, pkg) => {
39
40
  const registry = createRouteRegistry();
40
- const { route, wellKnown } = registry;
41
- const returned = await create({ ...recordingContext(pkg, 'api'), route, wellKnown });
41
+ const { route, wellKnown, files } = registry;
42
+ const returned = await create({ ...recordingContext(pkg, 'api'), route, wellKnown, files });
42
43
  return { routes: registry.routes, returned };
43
44
  };
44
45
  export const toolsOf = async (dir, pkg) => {
@@ -3,7 +3,7 @@ import {} from '../../manifest/manifest.schema.js';
3
3
  import { entryOf, normalizeParts } from '../../manifest/parts.js';
4
4
  import { IMAGE_PART_KINDS } from '../../manifest/primitives.schema.js';
5
5
  import {} from '../check.js';
6
- const PARTS = [...IMAGE_PART_KINDS, 'cli'];
6
+ const PARTS = [...IMAGE_PART_KINDS, 'cli', 'app'];
7
7
  const PART_FOLDER = /^(?:src|dist)\/(?:pages|ui|api|mcp|worker|cli)(?:\/|$)/;
8
8
  // Erased at build, so a type crosses no image; blanked keeping newlines for the line count.
9
9
  const TYPE_ONLY = /\b(?:import|export)\s+type\b[^;'"]*?from\s*(['"])[^'"]*\1/g;
@@ -29,6 +29,8 @@ const ON_STRINGS = [
29
29
  [/(?:from|import|require)\s*\(?\s*['"`](?:node:)?process['"`]/g, () => 'imports process'],
30
30
  [/(?:https?:)?\/\/[^'"`\s]*agentage\.io/gi, () => 'names an absolute agentage URL'],
31
31
  ];
32
+ // K10: an app calls its own api through useAppHost().api; a raw fetch is not stopped, so warned.
33
+ const APP_CODE = [[/\bfetch\s*\(/g, () => 'calls fetch(: an app uses useAppHost().api']];
32
34
  const matches = (file, text, patterns) => patterns.flatMap(([pattern, problem]) => [...text.matchAll(pattern)].map((m) => {
33
35
  const line = text.slice(0, m.index).split('\n').length;
34
36
  return { file, line, problem: problem(m) };
@@ -38,6 +40,8 @@ const fileFindings = (file, text) => {
38
40
  const kept = text.replace(TOKENS, (t) => (t.startsWith('/') ? t.replace(/[^\n]/g, '') : t));
39
41
  const code = kept.replace(QUOTED, (s) => (/\s/.test(s) ? "''" : s));
40
42
  const found = [...matches(file, code, ON_CODE), ...matches(file, kept, ON_STRINGS)];
43
+ if (file.startsWith('src/app/'))
44
+ found.push(...matches(file, code, APP_CODE).map((f) => ({ ...f, warning: true })));
41
45
  return [...found, ...crossPartImports(file, kept)];
42
46
  };
43
47
  const LINKED = 'is a symlink: part code is plain files';