@agentage/extension 0.5.0 → 0.5.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.
- package/dist/context/context.d.ts +2 -0
- package/dist/context/context.js +4 -0
- package/dist/context/test-context.d.ts +7 -0
- package/dist/context/test-context.js +9 -2
- package/dist/index.d.ts +2 -2
- package/dist/mcp/snapshot.d.ts +3 -0
- package/dist/mcp/snapshot.js +7 -0
- package/dist/testing/test-server.d.ts +4 -1
- package/dist/testing/test-server.js +5 -2
- package/dist/tool/check.d.ts +1 -0
- package/dist/tool/check.js +6 -3
- package/dist/tool/contracts.d.ts +1 -0
- package/dist/tool/contracts.js +48 -0
- package/dist/tool/index.d.ts +1 -0
- package/dist/tool/index.js +1 -0
- package/dist/tool/rules/folders.d.ts +4 -0
- package/dist/tool/rules/folders.js +38 -0
- package/dist/tool/rules/sealing.js +3 -1
- package/dist/tool/rules/surface.d.ts +4 -0
- package/dist/tool/rules/surface.js +9 -5
- package/dist/tool/up/health.d.ts +3 -0
- package/dist/tool/up/health.js +40 -0
- package/dist/tool/up/up.js +8 -3
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Caller } from '../auth/token-check.js';
|
|
2
2
|
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
3
|
+
import { type StoreKind } from '../manifest/primitives.schema.js';
|
|
3
4
|
import { type Log } from '../log/log.js';
|
|
4
5
|
import { type Store } from '../store/store.types.js';
|
|
5
6
|
import { type Secrets } from './secrets.js';
|
|
@@ -11,6 +12,7 @@ export interface ExtensionInfo {
|
|
|
11
12
|
part: ServerPartKind;
|
|
12
13
|
origin: string;
|
|
13
14
|
commit: string;
|
|
15
|
+
store?: StoreKind;
|
|
14
16
|
}
|
|
15
17
|
export interface PartContext {
|
|
16
18
|
readonly extension: Readonly<ExtensionInfo>;
|
package/dist/context/context.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { callerOf } from '../auth/token-check.js';
|
|
2
2
|
import {} from '../manifest/manifest.schema.js';
|
|
3
|
+
import { storeOf } from '../manifest/parts.js';
|
|
4
|
+
import {} from '../manifest/primitives.schema.js';
|
|
3
5
|
import { createLog } from '../log/log.js';
|
|
4
6
|
import {} from '../store/store.types.js';
|
|
5
7
|
import {} from './secrets.js';
|
|
@@ -12,12 +14,14 @@ export const NO_STORE = {
|
|
|
12
14
|
export const settingDefaults = (pkg) => Object.fromEntries(Object.entries(pkg.agentage.settings ?? {}).map(([key, setting]) => [key, setting.default]));
|
|
13
15
|
export const createContext = (input) => {
|
|
14
16
|
const { pkg, part, origin, commit, store } = input;
|
|
17
|
+
const kind = storeOf(pkg);
|
|
15
18
|
const extension = Object.freeze({
|
|
16
19
|
id: pkg.agentage.id,
|
|
17
20
|
version: pkg.version,
|
|
18
21
|
part,
|
|
19
22
|
origin,
|
|
20
23
|
commit,
|
|
24
|
+
...(kind && { store: kind }),
|
|
21
25
|
});
|
|
22
26
|
const log = input.log ?? createLog({ extension: pkg.agentage.id, part });
|
|
23
27
|
const settings = Object.freeze({ ...settingDefaults(pkg), ...input.settings });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type CliContext } from '../command/command.types.js';
|
|
2
2
|
import { type LogFields, type LogLevel } from '../log/log.js';
|
|
3
3
|
import { type ToolEntry, type ToolRegistrar } from '../mcp/tools.js';
|
|
4
|
+
import { type JobOptions } from '../worker/job-options.js';
|
|
4
5
|
import { type JobRun } from '../worker/runs.js';
|
|
5
6
|
import { type Schedule } from '../worker/scheduler.js';
|
|
6
7
|
import { type ExtensionInfo, type PartContext, type SettingValue } from './context.js';
|
|
@@ -16,8 +17,14 @@ export interface TestContext extends PartContext {
|
|
|
16
17
|
readonly schedule: Schedule;
|
|
17
18
|
readonly tool: ToolRegistrar;
|
|
18
19
|
readonly tools: ToolEntry[];
|
|
20
|
+
readonly jobs: ScheduledJob[];
|
|
19
21
|
runJob(name: string): Promise<JobRun | undefined>;
|
|
20
22
|
}
|
|
23
|
+
export interface ScheduledJob {
|
|
24
|
+
name: string;
|
|
25
|
+
cron: string;
|
|
26
|
+
options?: JobOptions;
|
|
27
|
+
}
|
|
21
28
|
export interface TestCommandContext extends CliContext {
|
|
22
29
|
readonly output: {
|
|
23
30
|
stdout: string[];
|
|
@@ -4,6 +4,7 @@ import { messageOf } from '../log/log.js';
|
|
|
4
4
|
import { createToolRegistry } from '../mcp/tools.js';
|
|
5
5
|
import { migrate } from '../store/migrations.js';
|
|
6
6
|
import { createTestStore } from '../store/test-store.js';
|
|
7
|
+
import {} from '../worker/job-options.js';
|
|
7
8
|
import { runLog } from '../worker/run-log.js';
|
|
8
9
|
import { memoryRuns } from '../worker/runs.js';
|
|
9
10
|
import { createScheduler } from '../worker/scheduler.js';
|
|
@@ -34,13 +35,19 @@ const TEST_EXTENSION = {
|
|
|
34
35
|
// Jobs run by hand with runJob, tools recorded as the mcp part registers them.
|
|
35
36
|
const recorders = (log) => {
|
|
36
37
|
const scheduler = createScheduler({ runs: memoryRuns(), log });
|
|
37
|
-
|
|
38
|
+
const jobs = [];
|
|
39
|
+
const schedule = (name, cron, job, options) => {
|
|
40
|
+
scheduler.schedule(name, cron, job, options);
|
|
41
|
+
jobs.push({ name, cron, options });
|
|
42
|
+
};
|
|
43
|
+
return { ...createToolRegistry(), schedule, jobs, runJob: scheduler.run };
|
|
38
44
|
};
|
|
39
45
|
const serverContext = (options) => {
|
|
40
46
|
const logs = [];
|
|
41
47
|
const log = runLog(recordingLog(logs));
|
|
42
48
|
const store = testStore(options.store, recordingLog([]));
|
|
43
|
-
const
|
|
49
|
+
const kind = options.store ? { store: 'postgres' } : {};
|
|
50
|
+
const extension = { ...TEST_EXTENSION, ...kind, ...options.extension };
|
|
44
51
|
const caller = { sub: 'usr_test', scopes: [`${extension.id}:read`] };
|
|
45
52
|
return {
|
|
46
53
|
extension,
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { type CliContext, type CliCreate, type CommandExtension, type CommandHan
|
|
|
3
3
|
export { type Out } from './command/out.js';
|
|
4
4
|
export { type ExtensionInfo, type PartContext, type ServerPartKind, type SettingValue, } from './context/context.js';
|
|
5
5
|
export { type Secrets } from './context/secrets.js';
|
|
6
|
-
export { createTestContext, type LogEntry, type TestCommandContext, type TestCommandOptions, type TestContext, type TestContextOptions, } from './context/test-context.js';
|
|
6
|
+
export { createTestContext, type LogEntry, type ScheduledJob, type TestCommandContext, type TestCommandOptions, type TestContext, type TestContextOptions, } from './context/test-context.js';
|
|
7
7
|
export { DiscoveryDocumentSchema, ExtensionRecordSchema, type DiscoveryDocument, type ExtensionRecord, } from './discovery/discovery.schema.js';
|
|
8
8
|
export { AGCID_HEADER, isAgcid } from './agcid/agcid.js';
|
|
9
9
|
export { ERROR_CODES, ERROR_STATUS, type ErrorCode } from './envelope/codes.js';
|
|
@@ -21,7 +21,7 @@ export { type McpContext, type ToolHandler, type ToolRegistrar, type ToolSpec, }
|
|
|
21
21
|
export { versionPage, type PagesContext, type PagesSite } from './pages/pages.js';
|
|
22
22
|
export { type ApiCreate, type ApiHandler, type ApiPart } from './server/part.types.js';
|
|
23
23
|
export { type QueryResult, type Row, type Store } from './store/store.types.js';
|
|
24
|
-
export { startTestMcp, startTestServer, type TestMcpOptions, type TestServer, type TestServerOptions, } from './testing/test-server.js';
|
|
24
|
+
export { startTestMcp, startTestServer, type TestMcp, type TestMcpOptions, type TestServer, type TestServerOptions, } from './testing/test-server.js';
|
|
25
25
|
export { type JobOptions } from './worker/job-options.js';
|
|
26
26
|
export { type JobRun, type RunStatus } from './worker/runs.js';
|
|
27
27
|
export { type Job, type Schedule } from './worker/scheduler.js';
|
package/dist/mcp/snapshot.d.ts
CHANGED
|
@@ -7,5 +7,8 @@ export interface McpSnapshot {
|
|
|
7
7
|
};
|
|
8
8
|
tools: Record<string, unknown>[];
|
|
9
9
|
}
|
|
10
|
+
type Json = Record<string, unknown>;
|
|
10
11
|
export declare const canonical: (value: unknown) => unknown;
|
|
11
12
|
export declare const mcpSnapshot: (url: string, version: ProtocolVersion) => Promise<McpSnapshot>;
|
|
13
|
+
export declare const callTool: (url: string, name: string, args: Json) => Promise<unknown>;
|
|
14
|
+
export {};
|
package/dist/mcp/snapshot.js
CHANGED
|
@@ -67,3 +67,10 @@ export const mcpSnapshot = async (url, version) => {
|
|
|
67
67
|
tools: listed['tools'],
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
+
// One tools/call as a stateless 2025-11-25 client sends it: the structured result, or a tool error thrown.
|
|
71
|
+
export const callTool = async (url, name, args) => {
|
|
72
|
+
const result = await post(url, '2025-11-25', 'tools/call', { name, arguments: args });
|
|
73
|
+
if (result['isError'])
|
|
74
|
+
throw new Error(`tool ${name}: ${JSON.stringify(result['content'])}`);
|
|
75
|
+
return result['structuredContent'];
|
|
76
|
+
};
|
|
@@ -14,5 +14,8 @@ export interface TestServer {
|
|
|
14
14
|
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
15
15
|
close(): Promise<void>;
|
|
16
16
|
}
|
|
17
|
+
export interface TestMcp extends TestServer {
|
|
18
|
+
call(name: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
19
|
+
}
|
|
17
20
|
export declare const startTestServer: <C extends PartContext = PartContext>(options: TestServerOptions<C>) => Promise<TestServer>;
|
|
18
|
-
export declare const startTestMcp: (options: TestMcpOptions) => Promise<
|
|
21
|
+
export declare const startTestMcp: (options: TestMcpOptions) => Promise<TestMcp>;
|
|
@@ -4,7 +4,8 @@ import {} from '../context/context.js';
|
|
|
4
4
|
import { createTestContext } from '../context/test-context.js';
|
|
5
5
|
import {} from '../manifest/manifest.schema.js';
|
|
6
6
|
import { createMcpApp } from '../mcp/mcp-app.js';
|
|
7
|
-
import {
|
|
7
|
+
import { callTool } from '../mcp/snapshot.js';
|
|
8
|
+
import { createToolRegistry, prefixed } from '../mcp/tools.js';
|
|
8
9
|
import { createApiApp } from '../server/app.js';
|
|
9
10
|
import {} from '../server/part.types.js';
|
|
10
11
|
import { listen } from '../server/serve.js';
|
|
@@ -44,5 +45,7 @@ export const startTestMcp = async (options) => {
|
|
|
44
45
|
tools: registry.tools,
|
|
45
46
|
listing: 'open',
|
|
46
47
|
});
|
|
47
|
-
|
|
48
|
+
const server = await startOn(app);
|
|
49
|
+
const call = (name, args = {}) => callTool(`${server.url}/mcp`, prefixed(ctx.extension.id, name), args);
|
|
50
|
+
return { ...server, call };
|
|
48
51
|
};
|
package/dist/tool/check.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface CheckReport {
|
|
|
32
32
|
problems: CheckProblem[];
|
|
33
33
|
skipped: Record<string, string>;
|
|
34
34
|
}
|
|
35
|
+
export declare const NOT_BUILT = "is missing: build the package first (npm run build)";
|
|
35
36
|
export declare const RULES: readonly CheckRule[];
|
|
36
37
|
export declare const check: (at: string, options?: CheckOptions) => Promise<CheckReport>;
|
|
37
38
|
export declare const assertConforms: (dir: string, options?: CheckOptions) => Promise<void>;
|
package/dist/tool/check.js
CHANGED
|
@@ -10,12 +10,14 @@ import {} from '../manifest/primitives.schema.js';
|
|
|
10
10
|
import { formatIssues, readJsonIfExists } from '../manifest/read-manifest.js';
|
|
11
11
|
import { runCommand } from './exec.js';
|
|
12
12
|
import { problemLines } from './format.js';
|
|
13
|
+
import { exportedPartCode } from './rules/folders.js';
|
|
13
14
|
import { sealing } from './rules/sealing.js';
|
|
14
15
|
import { store } from './rules/store.js';
|
|
15
16
|
import { surface } from './rules/surface.js';
|
|
16
17
|
import { KIT_VERSION } from './kit-version.js';
|
|
17
18
|
import { assertBuilt, exists } from './stage.js';
|
|
18
19
|
const RECIPE = /^(?:dockerfile|containerfile)(?:\..+)?$|^(?:docker-)?compose(?:\.[\w-]+)?\.ya?ml$/i;
|
|
20
|
+
export const NOT_BUILT = 'is missing: build the package first (npm run build)';
|
|
19
21
|
const NO_PACKAGE = 'is missing: run it in an extension package folder';
|
|
20
22
|
const manifest = {
|
|
21
23
|
name: 'manifest',
|
|
@@ -52,15 +54,16 @@ const partProblem = async ({ dir, pkg }, part) => {
|
|
|
52
54
|
return `${normalize(entryOf(pkg, part))} not found: the package build must write the cli part there`;
|
|
53
55
|
return part === 'ui' ? null : exportProblem(dir, pkg, part);
|
|
54
56
|
};
|
|
55
|
-
// Every part built
|
|
57
|
+
// Every part built and exporting only create; cli handlers = commands; exports hold no part code.
|
|
56
58
|
const entries = {
|
|
57
59
|
name: 'entries',
|
|
58
60
|
run: async (input) => {
|
|
59
61
|
if (!(await exists(join(input.dir, 'dist'))))
|
|
60
|
-
return [{ file: 'dist', problem:
|
|
62
|
+
return [{ file: 'dist', problem: NOT_BUILT }];
|
|
61
63
|
const parts = Object.keys(normalizeParts(input.pkg.agentage.parts).code);
|
|
62
64
|
const found = parts.map((part) => partProblem(input, part).catch(messageOf));
|
|
63
|
-
|
|
65
|
+
const problems = (await Promise.all(found)).flatMap((problem) => problem ? [{ problem }] : []);
|
|
66
|
+
return [...problems, ...exportedPartCode(input.pkg)];
|
|
64
67
|
},
|
|
65
68
|
};
|
|
66
69
|
const MAJORS = { express: '^5', zod: '^4', '@modelcontextprotocol/server': '^2' };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const writeContracts: (at: string) => Promise<string[]>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { OPENAPI_FILE } from '../discovery/openapi.js';
|
|
4
|
+
import { loadCreate } from '../manifest/entry.js';
|
|
5
|
+
import {} from '../manifest/manifest.schema.js';
|
|
6
|
+
import { normalizeParts } from '../manifest/parts.js';
|
|
7
|
+
import { readManifest } from '../manifest/read-manifest.js';
|
|
8
|
+
import { canonical } from '../mcp/snapshot.js';
|
|
9
|
+
import {} from '../mcp/tools.js';
|
|
10
|
+
import { NOT_BUILT } from './check.js';
|
|
11
|
+
import { generatedMcp } from './rules/surface.js';
|
|
12
|
+
import { exists } from './stage.js';
|
|
13
|
+
const readText = (file) => readFile(file, 'utf8').catch(() => undefined);
|
|
14
|
+
const sameJson = (text, value) => text !== undefined &&
|
|
15
|
+
JSON.stringify(canonical(JSON.parse(text))) === JSON.stringify(canonical(value));
|
|
16
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
17
|
+
const writeMcp = async (dir, pkg) => {
|
|
18
|
+
const file = `${pkg.agentage.id}.mcpc.json`;
|
|
19
|
+
const create = await loadCreate(dir, pkg, 'mcp');
|
|
20
|
+
const snapshot = canonical(await generatedMcp(create, pkg));
|
|
21
|
+
if (sameJson(await readText(join(dir, file)), snapshot))
|
|
22
|
+
return [];
|
|
23
|
+
await writeFile(join(dir, file), json(snapshot));
|
|
24
|
+
return [file];
|
|
25
|
+
};
|
|
26
|
+
const INFO_VERSION = /("info"\s*:\s*\{[^{}]*?"version"\s*:\s*)"[^"]*"/;
|
|
27
|
+
// Only info.version, in place so the file keeps its formatting; check reports any other drift.
|
|
28
|
+
const writeOpenapiVersion = async (dir, version) => {
|
|
29
|
+
const file = join(dir, OPENAPI_FILE);
|
|
30
|
+
const text = await readText(file);
|
|
31
|
+
if (text === undefined)
|
|
32
|
+
return [];
|
|
33
|
+
const inPlace = text.replace(INFO_VERSION, `$1${JSON.stringify(version)}`);
|
|
34
|
+
if (inPlace === text)
|
|
35
|
+
return [];
|
|
36
|
+
await writeFile(file, inPlace);
|
|
37
|
+
return [OPENAPI_FILE];
|
|
38
|
+
};
|
|
39
|
+
// check --write: the committed contracts regenerated from the built code; returns the files it changed.
|
|
40
|
+
export const writeContracts = async (at) => {
|
|
41
|
+
const dir = resolve(at);
|
|
42
|
+
const pkg = await readManifest(dir);
|
|
43
|
+
if (!(await exists(join(dir, 'dist'))))
|
|
44
|
+
throw new Error(`dist ${NOT_BUILT}`);
|
|
45
|
+
const { code } = normalizeParts(pkg.agentage.parts);
|
|
46
|
+
const mcp = code.mcp ? await writeMcp(dir, pkg) : [];
|
|
47
|
+
return [...mcp, ...(code.api ? await writeOpenapiVersion(dir, pkg.version) : [])];
|
|
48
|
+
};
|
package/dist/tool/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { type ExtensionPackage, type CommandSpec } from '../manifest/manifest.sc
|
|
|
4
4
|
export { readManifest, validateManifest } from '../manifest/read-manifest.js';
|
|
5
5
|
export { build, type BuildDeps, type BuildOptions, type BuildResult, type BuiltImage, } from './build.js';
|
|
6
6
|
export { check, type CheckProblem, type CheckReport } from './check.js';
|
|
7
|
+
export { writeContracts } from './contracts.js';
|
|
7
8
|
export { buildLines, checkLines } from './format.js';
|
|
8
9
|
export { KIT_VERSION } from './kit-version.js';
|
|
9
10
|
export { down, type DownOptions, type DownResult } from './up/down.js';
|
package/dist/tool/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export {} from '../manifest/manifest.schema.js';
|
|
|
4
4
|
export { readManifest, validateManifest } from '../manifest/read-manifest.js';
|
|
5
5
|
export { build, } from './build.js';
|
|
6
6
|
export { check } from './check.js';
|
|
7
|
+
export { writeContracts } from './contracts.js';
|
|
7
8
|
export { buildLines, checkLines } from './format.js';
|
|
8
9
|
export { KIT_VERSION } from './kit-version.js';
|
|
9
10
|
export { down } from './up/down.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ExtensionPackage } from '../../manifest/manifest.schema.js';
|
|
2
|
+
import { type Finding } from '../check.js';
|
|
3
|
+
export declare const crossPartImports: (file: string, code: string) => Finding[];
|
|
4
|
+
export declare const exportedPartCode: (pkg: ExtensionPackage) => Finding[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { normalize, posix } from 'node:path';
|
|
2
|
+
import {} from '../../manifest/manifest.schema.js';
|
|
3
|
+
import { entryOf, normalizeParts } from '../../manifest/parts.js';
|
|
4
|
+
import { IMAGE_PART_KINDS } from '../../manifest/primitives.schema.js';
|
|
5
|
+
import {} from '../check.js';
|
|
6
|
+
const PARTS = [...IMAGE_PART_KINDS, 'cli'];
|
|
7
|
+
const PART_FOLDER = /^(?:src|dist)\/(?:pages|ui|api|mcp|worker|cli)(?:\/|$)/;
|
|
8
|
+
// Erased at build, so a type crosses no image; blanked keeping newlines for the line count.
|
|
9
|
+
const TYPE_ONLY = /\b(?:import|export)\s+type\b[^;'"]*?from\s*(['"])[^'"]*\1/g;
|
|
10
|
+
const RELATIVE = /\b(?:from|import)\s*\(?\s*(['"])(\.{1,2}\/[^'"]*)\1/g;
|
|
11
|
+
// Each image carries one part folder and src/lib, so a part imports nothing else.
|
|
12
|
+
export const crossPartImports = (file, code) => {
|
|
13
|
+
const [src, part = ''] = file.split('/');
|
|
14
|
+
if (src !== 'src' || !PARTS.includes(part))
|
|
15
|
+
return [];
|
|
16
|
+
const values = code.replace(TYPE_ONLY, (t) => t.replace(/[^\n]/g, ''));
|
|
17
|
+
return [...values.matchAll(RELATIVE)].flatMap((m) => {
|
|
18
|
+
const target = posix.join(posix.dirname(file), m[2] ?? '');
|
|
19
|
+
if (target.startsWith(`src/${part}/`) || target.startsWith('src/lib/'))
|
|
20
|
+
return [];
|
|
21
|
+
const line = values.slice(0, m.index).split('\n').length;
|
|
22
|
+
return [
|
|
23
|
+
{ file, line, problem: `imports ${m[2]}: a part imports only its own folder and src/lib` },
|
|
24
|
+
];
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const targets = (value) => typeof value === 'string' ? [value] : Object.values(Object(value)).flatMap(targets);
|
|
28
|
+
// The package is the manifest and the record; part code reaches users only through its image.
|
|
29
|
+
export const exportedPartCode = (pkg) => {
|
|
30
|
+
const parts = Object.keys(normalizeParts(pkg.agentage.parts).code);
|
|
31
|
+
const entries = parts.map((part) => normalize(entryOf(pkg, part)));
|
|
32
|
+
const partCode = (target) => PART_FOLDER.test(normalize(target)) || entries.includes(normalize(target));
|
|
33
|
+
const exported = targets(pkg.exports).filter(partCode);
|
|
34
|
+
return exported.map((target) => ({
|
|
35
|
+
file: 'package.json',
|
|
36
|
+
problem: `exports ${target}: the package exports no part code`,
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
@@ -2,6 +2,7 @@ import { lstat, readdir, readFile } from 'node:fs/promises';
|
|
|
2
2
|
import { join, relative } from 'node:path';
|
|
3
3
|
import { readJsonIfExists } from '../../manifest/read-manifest.js';
|
|
4
4
|
import {} from '../check.js';
|
|
5
|
+
import { crossPartImports } from './folders.js';
|
|
5
6
|
const CODE = /\.[cm]?[jt]sx?$/;
|
|
6
7
|
const TEST = /\.(test|spec)\.[cm]?[jt]sx?$/;
|
|
7
8
|
// Strings first, so a // inside one is no comment; a comment keeps its newlines for the line count.
|
|
@@ -36,7 +37,8 @@ const matches = (file, text, patterns) => patterns.flatMap(([pattern, problem])
|
|
|
36
37
|
const fileFindings = (file, text) => {
|
|
37
38
|
const kept = text.replace(TOKENS, (t) => (t.startsWith('/') ? t.replace(/[^\n]/g, '') : t));
|
|
38
39
|
const code = kept.replace(QUOTED, (s) => (/\s/.test(s) ? "''" : s));
|
|
39
|
-
|
|
40
|
+
const found = [...matches(file, code, ON_CODE), ...matches(file, kept, ON_STRINGS)];
|
|
41
|
+
return [...found, ...crossPartImports(file, kept)];
|
|
40
42
|
};
|
|
41
43
|
const LINKED = 'is a symlink: part code is plain files';
|
|
42
44
|
// Every non-test source under src/; any symlink met is refused, since it could point anywhere.
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import { type ExtensionPackage } from '../../manifest/manifest.schema.js';
|
|
2
|
+
import { type McpSnapshot } from '../../mcp/snapshot.js';
|
|
3
|
+
import { type McpContext } from '../../mcp/tools.js';
|
|
1
4
|
import { type CheckRule } from '../check.js';
|
|
5
|
+
export declare const generatedMcp: (create: (ctx: McpContext) => unknown, pkg: ExtensionPackage) => Promise<McpSnapshot>;
|
|
2
6
|
export declare const surface: CheckRule;
|
|
@@ -2,6 +2,7 @@ import { join } from 'node:path';
|
|
|
2
2
|
import {} from '../../context/context.js';
|
|
3
3
|
import { OPENAPI_FILE, readOpenapi } from '../../discovery/openapi.js';
|
|
4
4
|
import { loadCreate } from '../../manifest/entry.js';
|
|
5
|
+
import {} from '../../manifest/manifest.schema.js';
|
|
5
6
|
import { normalizeParts } from '../../manifest/parts.js';
|
|
6
7
|
import { readJsonIfExists } from '../../manifest/read-manifest.js';
|
|
7
8
|
import { canonical } from '../../mcp/snapshot.js';
|
|
@@ -63,18 +64,21 @@ const byName = ({ serverInfo, tools }) => ({
|
|
|
63
64
|
serverInfo,
|
|
64
65
|
...Object.fromEntries(tools.map((tool) => [String(tool['name']), tool])),
|
|
65
66
|
});
|
|
67
|
+
// The tool list the mcp part serves, generated from its code: what {id}.mcpc.json must hold.
|
|
68
|
+
export const generatedMcp = async (create, pkg) => {
|
|
69
|
+
const { id } = pkg.agentage;
|
|
70
|
+
const tools = (await registeredTools(create, pkg)).map((tool) => listed(id, tool));
|
|
71
|
+
return { serverInfo: { name: `agentage-${id}`, version: pkg.version }, tools };
|
|
72
|
+
};
|
|
66
73
|
const mcpSurface = async ({ dir, pkg }) => {
|
|
67
74
|
const create = await loadCreate(dir, pkg, 'mcp').catch(() => null);
|
|
68
75
|
if (!create)
|
|
69
76
|
return [];
|
|
70
|
-
const
|
|
71
|
-
const file = `${id}.mcpc.json`;
|
|
77
|
+
const file = `${pkg.agentage.id}.mcpc.json`;
|
|
72
78
|
const committed = (await readJsonIfExists(join(dir, file)));
|
|
73
79
|
if (!committed)
|
|
74
80
|
return [{ file, problem: 'is missing: the mcp part commits its tool list' }];
|
|
75
|
-
const
|
|
76
|
-
const serverInfo = { name: `agentage-${id}`, version: pkg.version };
|
|
77
|
-
const diff = differing(byName({ serverInfo, tools }), byName(committed));
|
|
81
|
+
const diff = differing(byName(await generatedMcp(create, pkg)), byName(committed));
|
|
78
82
|
const problem = `differs from the generated tool list (${diff.join(', ')})`;
|
|
79
83
|
return diff.length > 0 ? [{ file, problem }] : [];
|
|
80
84
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {} from '../exec.js';
|
|
2
|
+
import { compose } from './compose-run.js';
|
|
3
|
+
import { PART_PORT } from './gateway.js';
|
|
4
|
+
// Inside the container: parts publish no host port, and the image always has node.
|
|
5
|
+
const FETCH = `fetch('http://127.0.0.1:${PART_PORT}/health').then(async (r) => process.stdout.write(await r.text()))`;
|
|
6
|
+
const dataOf = (text) => {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(text).data;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
// 200 ok or degraded is an answering part (the /health standard); only unavailable fails.
|
|
15
|
+
const wants = (part, commit) => [
|
|
16
|
+
['status', (v) => v === 'ok' || v === 'degraded', 'ok or degraded'],
|
|
17
|
+
['commit', (v) => v === commit, commit],
|
|
18
|
+
['part', (v) => v === part, part],
|
|
19
|
+
];
|
|
20
|
+
// The first field that differs from the build, as one FAIL line.
|
|
21
|
+
const mismatch = (part, commit, data, text) => {
|
|
22
|
+
if (!data)
|
|
23
|
+
return `FAIL ${part} /health body is not the health envelope: ${text.slice(0, 120)}`;
|
|
24
|
+
const bad = wants(part, commit).find(([field, fits]) => !fits(data[field]));
|
|
25
|
+
return bad && `FAIL ${part} /health ${bad[0]} ${String(data[bad[0]])}, needs ${bad[2]}`;
|
|
26
|
+
};
|
|
27
|
+
const notOk = (data) => Object.entries(Object(data['checks']))
|
|
28
|
+
.filter(([, status]) => status !== 'ok')
|
|
29
|
+
.map(([name, status]) => `${name} ${String(status)}`)
|
|
30
|
+
.join(' · ');
|
|
31
|
+
// Docker's healthy only says the probe answered; the body must name this build and this part.
|
|
32
|
+
export const assertHealthBodies = async (run, target, parts, commit) => {
|
|
33
|
+
const read = parts.map((part) => compose(run, target, ['exec', '-T', part, 'node', '-e', FETCH]));
|
|
34
|
+
const bodies = await Promise.all(read);
|
|
35
|
+
const data = bodies.map(dataOf);
|
|
36
|
+
const failed = parts.flatMap((part, i) => mismatch(part, commit, data[i], bodies[i] ?? '') ?? []);
|
|
37
|
+
if (failed.length > 0)
|
|
38
|
+
throw new Error(failed.join('\n'));
|
|
39
|
+
return parts.flatMap((part, i) => data[i]?.['status'] === 'degraded' ? [[part, notOk(data[i])]] : []);
|
|
40
|
+
};
|
package/dist/tool/up/up.js
CHANGED
|
@@ -17,6 +17,7 @@ import { assertPortsFree } from './ports.js';
|
|
|
17
17
|
import { writeUpSecrets } from './secrets.js';
|
|
18
18
|
import { projectName, workingCopy } from './project.js';
|
|
19
19
|
import { storePhrase, summaryOf } from './store-line.js';
|
|
20
|
+
import { assertHealthBodies } from './health.js';
|
|
20
21
|
import { waitHealthy } from './wait.js';
|
|
21
22
|
const GATEWAY = `http://localhost:${GATEWAY_PORT}`;
|
|
22
23
|
const jsonFile = (file, value) => writeFile(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
@@ -37,6 +38,7 @@ const buildStep = async (s, env) => {
|
|
|
37
38
|
assertDiscoverable(record, GATEWAY);
|
|
38
39
|
s.line('record', `${LOCAL_DIR}/record.json`, 'discovery valid');
|
|
39
40
|
await renderFiles(s, file, Object.fromEntries(built.images.map((i) => [i.part, i.tag])));
|
|
41
|
+
return built.commit;
|
|
40
42
|
};
|
|
41
43
|
// The migrate job runs before any part starts; a kept volume reports what it already had.
|
|
42
44
|
const storeStep = async (s) => {
|
|
@@ -52,9 +54,12 @@ const storeStep = async (s) => {
|
|
|
52
54
|
export const routesOf = (pkg) => Object.keys(PART_PATHS)
|
|
53
55
|
.filter((part) => imageParts(pkg).includes(part))
|
|
54
56
|
.map((part) => partPath(part, pkg.version));
|
|
55
|
-
const partsStep = async (s) => {
|
|
57
|
+
const partsStep = async (s, commit) => {
|
|
56
58
|
await compose(s.deps.run, s.target, ['up', '-d', '--remove-orphans'], TIMEOUTS.start);
|
|
57
59
|
await waitHealthy(s.target, [...imageParts(s.pkg), 'gateway', 'issuer'], s.deps);
|
|
60
|
+
const degraded = await assertHealthBodies(s.deps.run, s.target, imageParts(s.pkg), commit);
|
|
61
|
+
for (const [part, checks] of degraded)
|
|
62
|
+
s.line('degraded', part, checks);
|
|
58
63
|
s.line('issuer', 'dev tokens', `http://localhost:${ISSUER_PORT}`);
|
|
59
64
|
s.line('gateway', GATEWAY, routesOf(s.pkg).join(' · '));
|
|
60
65
|
};
|
|
@@ -74,12 +79,12 @@ export const up = async (options = {}, deps = { run: runCommand }) => {
|
|
|
74
79
|
const started = Date.now();
|
|
75
80
|
const s = await sessionOf(options, deps);
|
|
76
81
|
await assertPortsFree(s.deps.run, s.target.project);
|
|
77
|
-
await buildStep(s, options.env ?? process.env);
|
|
82
|
+
const commit = await buildStep(s, options.env ?? process.env);
|
|
78
83
|
// Again after the build: another up may have started meanwhile, and the store comes next.
|
|
79
84
|
await assertPortsFree(s.deps.run, s.target.project);
|
|
80
85
|
if (hasStore(s.pkg, 'postgres'))
|
|
81
86
|
await storeStep(s);
|
|
82
|
-
await partsStep(s);
|
|
87
|
+
await partsStep(s, commit);
|
|
83
88
|
const parts = imageParts(s.pkg).length + (hasStore(s.pkg, 'postgres') ? 1 : 0) + cliParts(s.pkg);
|
|
84
89
|
const seconds = Math.round((Date.now() - started) / 1000);
|
|
85
90
|
s.line('ready', `${plural(parts, 'part')} healthy`, `${seconds} s`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "The agentage extension kit: create(ctx) per part (pages, ui, api, mcp, worker, cli), the store, /health, discovery, the envelope, and the build tool with up and token",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|