@agentage/cli 0.52.1 → 0.54.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.
- package/README.md +9 -11
- package/dist/commands/daemon/daemon.d.ts +5 -3
- package/dist/commands/daemon/daemon.js +45 -10
- package/dist/commands/daemon/installer.d.ts +4 -0
- package/dist/commands/daemon/installer.js +32 -8
- package/dist/commands/daemon/run.d.ts +3 -0
- package/dist/commands/daemon/run.js +11 -1
- package/dist/commands/extension/build.js +5 -3
- package/dist/commands/extension/configure.js +2 -1
- package/dist/commands/extension/create-install.js +3 -2
- package/dist/commands/extension/install-once.d.ts +2 -0
- package/dist/commands/extension/install-once.js +5 -5
- package/dist/commands/extension/install-spec.d.ts +7 -0
- package/dist/commands/extension/install-spec.js +33 -0
- package/dist/commands/extension/lifecycle.d.ts +1 -4
- package/dist/commands/extension/lifecycle.js +8 -32
- package/dist/commands/extension/package-build.d.ts +11 -1
- package/dist/commands/extension/package-build.js +53 -17
- package/dist/commands/extension/release-guard.d.ts +8 -1
- package/dist/commands/extension/release-guard.js +39 -16
- package/dist/commands/extension/release.js +35 -19
- package/dist/commands/extension/setup-install.js +48 -23
- package/dist/commands/extension/setup-marker.d.ts +6 -0
- package/dist/commands/extension/setup-marker.js +23 -0
- package/dist/commands/extension/up-build.d.ts +17 -0
- package/dist/commands/extension/up-build.js +71 -0
- package/dist/commands/extension/up-commands.js +11 -10
- package/dist/commands/extension/up-local.d.ts +15 -12
- package/dist/commands/extension/up-local.js +61 -60
- package/dist/commands/extension/up-reload.d.ts +30 -0
- package/dist/commands/extension/up-reload.js +115 -0
- package/dist/commands/extension/up-run.d.ts +9 -11
- package/dist/commands/extension/up-run.js +132 -50
- package/dist/commands/extension/up-watch.d.ts +23 -0
- package/dist/commands/extension/up-watch.js +81 -0
- package/dist/commands/extension/up.d.ts +5 -3
- package/dist/commands/extension/up.js +48 -25
- package/dist/core/installer/version-spec.d.ts +2 -0
- package/dist/core/installer/version-spec.js +5 -0
- package/dist/core/loader/manifest.d.ts +2 -1
- package/dist/core/loader/manifest.js +13 -8
- package/dist/lib/daemon/daemon-client.js +16 -11
- package/dist/lib/daemon/daemon-file.d.ts +2 -0
- package/dist/lib/daemon/daemon-file.js +4 -0
- package/dist/lib/daemon/daemon-health.d.ts +5 -0
- package/dist/lib/daemon/daemon-health.js +27 -2
- package/dist/lib/daemon/daemon-probe.d.ts +10 -5
- package/dist/lib/daemon/daemon-probe.js +8 -2
- package/dist/lib/daemon/host-client.d.ts +17 -2
- package/dist/lib/daemon/host-client.js +42 -12
- package/dist/lib/fs/file-lock.js +6 -0
- package/dist/lib/json-output.js +7 -5
- package/dist/lib/proc/start-time.d.ts +10 -0
- package/dist/lib/proc/start-time.js +46 -0
- package/dist/program-deps.js +3 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuiltImage } from '@agentage/extension/tool';
|
|
1
|
+
import type { BuiltImage, ExtensionPackage } from '@agentage/extension/tool';
|
|
2
2
|
export type Ran = {
|
|
3
3
|
ok: boolean;
|
|
4
4
|
out: string;
|
|
@@ -7,8 +7,15 @@ export type Ran = {
|
|
|
7
7
|
export type Exec = (cmd: string, args: string[], env?: NodeJS.ProcessEnv) => Promise<Ran>;
|
|
8
8
|
export declare const execIn: (cwd: string, seconds?: number) => Exec;
|
|
9
9
|
export declare const RECORD = "agentage-extension.json";
|
|
10
|
+
export declare const CONTAINER_RECORD = "agentage-container.json";
|
|
11
|
+
export declare const PART_SUFFIX: RegExp;
|
|
10
12
|
export declare const IMAGE_PARTS: readonly BuiltImage['part'][];
|
|
13
|
+
export declare const imagesOf: (pkg: ExtensionPackage) => {
|
|
14
|
+
parts: ("api" | "worker" | "pages" | "ui" | "mcp")[];
|
|
15
|
+
oneImage: boolean;
|
|
16
|
+
};
|
|
11
17
|
export type GuardInput = Record<'dir' | 'tag' | 'sha' | 'repo' | 'id' | 'version', string> & {
|
|
12
18
|
parts: readonly BuiltImage['part'][];
|
|
19
|
+
oneImage: boolean;
|
|
13
20
|
};
|
|
14
21
|
export declare const releaseGuard: (g: GuardInput, exec: Exec) => Promise<"build" | "reuse">;
|
|
@@ -17,47 +17,70 @@ export const execIn = (cwd, seconds = 0) => (cmd, args, env) => new Promise((res
|
|
|
17
17
|
child.stdin?.end();
|
|
18
18
|
});
|
|
19
19
|
export const RECORD = 'agentage-extension.json';
|
|
20
|
+
// The record of the one image (build --container --push), attached beside RECORD.
|
|
21
|
+
export const CONTAINER_RECORD = 'agentage-container.json';
|
|
22
|
+
// An id with a part suffix names the part image of another extension (market-api).
|
|
23
|
+
export const PART_SUFFIX = /-(pages|ui|api|mcp|worker)$/;
|
|
20
24
|
export const IMAGE_PARTS = ['pages', 'ui', 'api', 'mcp', 'worker'];
|
|
25
|
+
const declared = (pkg, part) => (pkg.agentage.parts[part] ?? false) !== false;
|
|
26
|
+
// The part images, and the one image when the package has a server part for it to run.
|
|
27
|
+
export const imagesOf = (pkg) => ({
|
|
28
|
+
parts: IMAGE_PARTS.filter((part) => declared(pkg, part)),
|
|
29
|
+
oneImage: ['api', 'mcp', 'worker'].some((part) => declared(pkg, part)),
|
|
30
|
+
});
|
|
21
31
|
// Only "not found" means "not released"; any other failure stops the release, never rebuilds it.
|
|
22
32
|
const notFound = (ran, pattern, what) => {
|
|
23
33
|
if (!pattern.test(ran.err))
|
|
24
34
|
throw new Error(`cannot tell whether ${what} exists: ${ran.err}`);
|
|
25
35
|
};
|
|
26
|
-
const
|
|
36
|
+
const downloadOf = (g, name, exec) => exec('gh', ['release', 'download', g.tag, '-R', g.repo, '-p', name, '-O', '-']);
|
|
37
|
+
const reuse = async (g, json, exec) => {
|
|
38
|
+
const { dir, tag, sha } = g;
|
|
27
39
|
const { commit } = JSON.parse(json);
|
|
28
40
|
if (commit !== sha) {
|
|
29
41
|
const moved = `${tag} was released from ${String(commit)}, not ${sha}`;
|
|
30
42
|
throw new Error(`${moved}; a version's images never change: release a new version`);
|
|
31
43
|
}
|
|
44
|
+
// The container record is uploaded first: a part record without it is a half-done release.
|
|
45
|
+
if (g.oneImage && !(await downloadOf(g, CONTAINER_RECORD, exec)).ok)
|
|
46
|
+
throw new Error(`${tag} has ${RECORD} but no ${CONTAINER_RECORD}; its one image has no record: release a new version`);
|
|
32
47
|
await mkdir(join(dir, 'dist'), { recursive: true });
|
|
33
48
|
await writeFile(join(dir, 'dist', RECORD), `${json.trimEnd()}\n`);
|
|
34
49
|
return 'reuse';
|
|
35
50
|
};
|
|
51
|
+
const refsOf = (g) => [
|
|
52
|
+
...g.parts.map((part) => `ghcr.io/agentage/${g.id}-${part}:${g.version}`),
|
|
53
|
+
...(g.oneImage ? [`ghcr.io/agentage/${g.id}:${g.version}`] : []),
|
|
54
|
+
];
|
|
55
|
+
// GHCR answers denied for a new name too: the GitHub API tells a new package from another repo's.
|
|
56
|
+
const ownsName = async (g, exec) => {
|
|
57
|
+
const got = await exec('gh', ['api', `/orgs/agentage/packages/container/${g.id}`]);
|
|
58
|
+
if (!got.ok)
|
|
59
|
+
return notFound(got, /404|Not Found/, `the package ghcr.io/agentage/${g.id}`);
|
|
60
|
+
const { repository } = JSON.parse(got.out);
|
|
61
|
+
if (repository?.full_name !== g.repo)
|
|
62
|
+
throw new Error(`ghcr.io/agentage/${g.id} is denied: the name ${g.id} belongs to another package`);
|
|
63
|
+
};
|
|
36
64
|
const ensureNoImages = async (g, exec) => {
|
|
37
|
-
for (const
|
|
38
|
-
const image = `ghcr.io/agentage/${g.id}-${part}:${g.version}`;
|
|
65
|
+
for (const image of refsOf(g)) {
|
|
39
66
|
const ran = await exec('docker', ['manifest', 'inspect', image]);
|
|
40
67
|
if (ran.ok)
|
|
41
68
|
throw new Error(`${image} is already pushed but ${g.tag} has no record; release a new version`);
|
|
42
|
-
//
|
|
69
|
+
// A part may be new: GHCR can answer denied for it. Denied for the plain id (the one image)
|
|
70
|
+
// may be another package's name, which would fail the push after the part images.
|
|
71
|
+
const one = g.oneImage && image === `ghcr.io/agentage/${g.id}:${g.version}`;
|
|
72
|
+
if (one && /denied/.test(ran.err)) {
|
|
73
|
+
await ownsName(g, exec);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
43
76
|
notFound(ran, /manifest unknown|no such manifest|denied/, image);
|
|
44
77
|
}
|
|
45
78
|
};
|
|
46
79
|
// A released version is never rebuilt: its images and record stay as first pushed.
|
|
47
80
|
export const releaseGuard = async (g, exec) => {
|
|
48
|
-
const record = await
|
|
49
|
-
'release',
|
|
50
|
-
'download',
|
|
51
|
-
g.tag,
|
|
52
|
-
'-R',
|
|
53
|
-
g.repo,
|
|
54
|
-
'-p',
|
|
55
|
-
RECORD,
|
|
56
|
-
'-O',
|
|
57
|
-
'-',
|
|
58
|
-
]);
|
|
81
|
+
const record = await downloadOf(g, RECORD, exec);
|
|
59
82
|
if (record.ok)
|
|
60
|
-
return reuse(g, record.out);
|
|
83
|
+
return reuse(g, record.out, exec);
|
|
61
84
|
notFound(record, /release not found|no assets match|no assets to download/, `the ${g.tag} release record`);
|
|
62
85
|
await ensureNoImages(g, exec);
|
|
63
86
|
return 'build';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { mkdtemp, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { mkdtemp, readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import {} from 'commander';
|
|
5
5
|
import { addJson, CliError } from '../../lib/json-output.js';
|
|
6
6
|
import { runImageBuild } from './build.js';
|
|
7
7
|
import { loadKitTool } from './kit-tool.js';
|
|
8
|
-
import { execIn,
|
|
8
|
+
import { CONTAINER_RECORD, execIn, imagesOf, PART_SUFFIX, RECORD, releaseGuard, } from './release-guard.js';
|
|
9
|
+
import {} from './release-guard.js';
|
|
9
10
|
const defaultDeps = { exec: execIn, tool: loadKitTool, env: process.env };
|
|
10
11
|
const step = (line) => console.log(`PASS ${line}`);
|
|
11
12
|
const fail = (line) => {
|
|
@@ -20,17 +21,31 @@ const takeSecrets = (env) => {
|
|
|
20
21
|
return { gh: gh ? { GH_TOKEN: gh } : {}, npm: NPM_TOKEN ? { NPM_TOKEN } : {} };
|
|
21
22
|
};
|
|
22
23
|
const scoped = (exec, secrets) => (cmd, args) => exec(cmd, args, secrets[cmd]);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
// Every image is pushed first. The records go up one call each, RECORD last: it is the "done" marker.
|
|
25
|
+
const attach = async (run, tag, repo, names) => {
|
|
26
|
+
const notes = ['--title', tag, '--notes', `Images by digest: ${names.join(', ')}`];
|
|
27
|
+
let exists = (await run('gh', ['release', 'view', tag, '-R', repo])).ok;
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
const file = join('dist', name);
|
|
30
|
+
const args = exists ? ['upload', tag, file] : ['create', tag, file, ...notes];
|
|
31
|
+
const ran = await run('gh', ['release', ...args, '-R', repo]);
|
|
32
|
+
if (!ran.ok)
|
|
33
|
+
fail(`record: ${ran.err}`);
|
|
34
|
+
exists = true;
|
|
35
|
+
}
|
|
36
|
+
step(`record: ${names.join(', ')} attached to release ${tag}`);
|
|
37
|
+
};
|
|
38
|
+
// The part images (v13 rows, the estate) and the one image (app hosts), all pushed by digest.
|
|
39
|
+
const buildImages = async (dir, oneImage, tool) => {
|
|
40
|
+
await runImageBuild({ push: true, dir }, tool);
|
|
41
|
+
if (!oneImage)
|
|
42
|
+
return [RECORD];
|
|
43
|
+
// The second compile may clean dist/: the part record is kept and written back.
|
|
44
|
+
const record = await readFile(join(dir, 'dist', RECORD));
|
|
45
|
+
// The first build checked this HEAD; its own dist/ output must not read as a change.
|
|
46
|
+
await runImageBuild({ push: true, container: true, dir }, tool, async () => undefined);
|
|
47
|
+
await writeFile(join(dir, 'dist', RECORD), record);
|
|
48
|
+
return [CONTAINER_RECORD, RECORD];
|
|
34
49
|
};
|
|
35
50
|
// Single quotes on purpose: npm expands ${NPM_TOKEN} itself, the token never lands on disk.
|
|
36
51
|
const tokenConfig = async (token) => {
|
|
@@ -87,6 +102,8 @@ const preflight = async (run, pkg, tag, sha, isPrivate) => {
|
|
|
87
102
|
if (pkg.agentage.id === 'template')
|
|
88
103
|
fail('id: this repo is the starting point for extensions: create one, release that');
|
|
89
104
|
step(`id: ${pkg.agentage.id} is not the template`);
|
|
105
|
+
if (imagesOf(pkg).oneImage && PART_SUFFIX.test(pkg.agentage.id))
|
|
106
|
+
fail(`id: ${pkg.agentage.id} ends in a part name: it would name another extension's image`);
|
|
90
107
|
const fetched = await run('git', ['fetch', '-q', 'origin', 'master']);
|
|
91
108
|
if (!fetched.ok || !(await run('git', ['merge-base', '--is-ancestor', sha, 'origin/master'])).ok)
|
|
92
109
|
fail(`master: ${sha} is not on master${fetched.err ? `: ${fetched.err}` : ''}`);
|
|
@@ -110,15 +127,14 @@ export const runExtensionRelease = async ({ dir = '.', timeout = 60 } = {}, deps
|
|
|
110
127
|
const isPrivate = pkg['private'] === true;
|
|
111
128
|
await preflight(run, pkg, tag, sha, isPrivate);
|
|
112
129
|
const { id } = pkg.agentage;
|
|
113
|
-
const
|
|
130
|
+
const { parts, oneImage } = imagesOf(pkg);
|
|
131
|
+
const g = { dir, tag, sha, repo, id, version: pkg.version, parts, oneImage };
|
|
114
132
|
const decision = await releaseGuard(g, run).catch((e) => fail(`guard: ${e.message}`));
|
|
115
133
|
const build = decision === 'build';
|
|
116
134
|
const done = isPrivate ? 'is released' : 'is released: npm only';
|
|
117
135
|
step(`guard: ${tag} ${build ? 'has no record and no image: build' : done}`);
|
|
118
|
-
if (build)
|
|
119
|
-
await
|
|
120
|
-
await attach(run, tag, repo);
|
|
121
|
-
}
|
|
136
|
+
if (build)
|
|
137
|
+
await attach(run, tag, repo, await buildImages(dir, oneImage, deps.tool));
|
|
122
138
|
if (isPrivate)
|
|
123
139
|
step('npm: private package, not published');
|
|
124
140
|
else
|
|
@@ -128,7 +144,7 @@ export const runExtensionRelease = async ({ dir = '.', timeout = 60 } = {}, deps
|
|
|
128
144
|
export const addRelease = (group, release) => {
|
|
129
145
|
addJson(group
|
|
130
146
|
.command('release')
|
|
131
|
-
.description('Release an extension from its v* tag in CI: guard, images,
|
|
147
|
+
.description('Release an extension from its v* tag in CI: guard, images, one image, records, npm package')
|
|
132
148
|
.option('--dir <path>', 'the extension package folder (default: the current folder)')
|
|
133
149
|
.option('--timeout <seconds>', 'bound on each git, GitHub and npm check (default: 60; npm publish: 300)', Number)).action(release);
|
|
134
150
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs';
|
|
2
1
|
import {} from '../../core/profile/schema.js';
|
|
3
2
|
import {} from '../../lib/daemon/host-client.js';
|
|
4
3
|
import { CliError, messageOf } from '../../lib/json-output.js';
|
|
5
4
|
import { line } from './line.js';
|
|
6
5
|
import { addOnce } from './install-once.js';
|
|
7
|
-
import {
|
|
6
|
+
import { NOT_EXTENSION, profileEntries } from './profile-plan.js';
|
|
7
|
+
import { readMarker, writeMarker } from './setup-marker.js';
|
|
8
8
|
const EXACT = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
9
9
|
const KEPT = 'your account profile was installed here already; setup installs nothing (agentage extension install)';
|
|
10
10
|
// An exact version is sent as it is; a range installs the market's newest version.
|
|
@@ -15,8 +15,7 @@ const installOne = async (host, entry) => {
|
|
|
15
15
|
const { row, already } = await addOnce(host, { ...bodyOf(entry.id, entry.range), ...off });
|
|
16
16
|
return already ? { ...row, already } : row;
|
|
17
17
|
};
|
|
18
|
-
// A
|
|
19
|
-
// A problem is the line under "not installed": the entry failed to install or to start.
|
|
18
|
+
// A problem: no row (install failed) or a failed row; a non-extension package is only said.
|
|
20
19
|
const tryOne = async (host, entry) => {
|
|
21
20
|
if (entry.id === null)
|
|
22
21
|
return void console.log(`${entry.name}: ${NOT_EXTENSION}`);
|
|
@@ -26,31 +25,57 @@ const tryOne = async (host, entry) => {
|
|
|
26
25
|
error: messageOf(err),
|
|
27
26
|
}));
|
|
28
27
|
if ('error' in row && !('state' in row))
|
|
29
|
-
return `${id}: ${row.error}
|
|
30
|
-
if ('already' in row)
|
|
28
|
+
return { id, row: false, text: `${id}: ${row.error}` };
|
|
29
|
+
if ('already' in row && row.state !== 'failed')
|
|
31
30
|
return void console.log(`${id} already installed`);
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
if (!('already' in row))
|
|
32
|
+
console.log(`${row.id} ${row.version} ${row.state}`);
|
|
33
|
+
const failed = row.state === 'failed';
|
|
34
|
+
return failed ? { id, row: true, text: `${id}: ${row.error ?? 'failed'}` } : undefined;
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const AGAIN = 'the next setup tries those entries again';
|
|
37
|
+
const notInstalled = (problems, account) => new CliError('extension_failed', ['not installed:', ...problems.map((p) => ` ${p.text}`), ...(account ? [AGAIN] : [])].join('\n'));
|
|
38
|
+
// A retry is only the ids that failed; one whose failed row the user removed is not added again.
|
|
39
|
+
const retryEntries = async (host, entries, failed) => {
|
|
40
|
+
const ids = new Set((await host.list()).map((row) => row.id));
|
|
41
|
+
return entries.filter((entry) => {
|
|
42
|
+
const was = failed.find((f) => f.id === entry.id);
|
|
43
|
+
if (!was)
|
|
44
|
+
return false;
|
|
45
|
+
if (!was.row || ids.has(was.id))
|
|
46
|
+
return true;
|
|
47
|
+
console.log(`${was.id} was removed here; setup does not add it again`);
|
|
48
|
+
return false;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const tryAll = async (host, entries) => {
|
|
52
|
+
const problems = [];
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
const problem = await tryOne(host, entry);
|
|
55
|
+
if (problem)
|
|
56
|
+
problems.push(problem);
|
|
57
|
+
}
|
|
58
|
+
return problems;
|
|
59
|
+
};
|
|
60
|
+
// Plain setup tries each entry once per machine, then only the ids the marker names as failed.
|
|
37
61
|
export const installThroughDaemon = async (profile, deps) => {
|
|
38
62
|
const account = deps.from === 'account';
|
|
39
|
-
|
|
63
|
+
const failed = account ? readMarker() : null;
|
|
64
|
+
if (failed?.length === 0)
|
|
40
65
|
return console.log(line('extensions', KEPT));
|
|
41
66
|
const entries = profileEntries(profile);
|
|
42
67
|
if (entries.length > 0 && deps.daemonOff)
|
|
43
68
|
return console.log(line('extensions', 'the daemon is off, nothing installed'));
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
if (entries.length === 0)
|
|
70
|
+
return;
|
|
71
|
+
const host = await deps.host();
|
|
72
|
+
const problems = await tryAll(host, failed ? await retryEntries(host, entries, failed) : entries);
|
|
73
|
+
if (account)
|
|
74
|
+
writeMarker(problems.map(({ id, row }) => ({ id, row })));
|
|
75
|
+
if (problems.length === 0)
|
|
76
|
+
return;
|
|
77
|
+
if (!failed)
|
|
78
|
+
throw notInstalled(problems, account);
|
|
79
|
+
for (const p of problems)
|
|
80
|
+
console.log(`${p.text} (still fails; the next setup tries it again)`);
|
|
56
81
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { isRecord } from '../../lib/fs/json-file.js';
|
|
4
|
+
import { profileMarkerPath } from './profile-plan.js';
|
|
5
|
+
const isFailed = (value) => isRecord(value) && typeof value['id'] === 'string' && typeof value['row'] === 'boolean';
|
|
6
|
+
// null: no marker. A marker of cli 0.52 (a time line) or one that is not JSON has nothing to retry.
|
|
7
|
+
export const readMarker = () => {
|
|
8
|
+
if (!existsSync(profileMarkerPath()))
|
|
9
|
+
return null;
|
|
10
|
+
try {
|
|
11
|
+
const doc = JSON.parse(readFileSync(profileMarkerPath(), 'utf8'));
|
|
12
|
+
const failed = isRecord(doc) && Array.isArray(doc['failed']) ? doc['failed'] : [];
|
|
13
|
+
return failed.filter(isFailed);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const writeMarker = (failed) => {
|
|
20
|
+
mkdirSync(dirname(profileMarkerPath()), { recursive: true });
|
|
21
|
+
const doc = { installedAt: new Date().toISOString(), failed };
|
|
22
|
+
writeFileSync(profileMarkerPath(), `${JSON.stringify(doc)}\n`, { mode: 0o600 });
|
|
23
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Npm } from './package-build.js';
|
|
2
|
+
export type UpMode = {
|
|
3
|
+
kind: 'tsc';
|
|
4
|
+
tsc: string;
|
|
5
|
+
config: string;
|
|
6
|
+
rest: string | null;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'stage';
|
|
9
|
+
script: string | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const NEXT = "dist.next";
|
|
12
|
+
export declare const upModeOf: (dir: string) => UpMode;
|
|
13
|
+
export declare const seedNext: (dir: string) => void;
|
|
14
|
+
export declare const stageOf: (dir: string) => string;
|
|
15
|
+
export declare const removeStage: (dir: string) => void;
|
|
16
|
+
export declare const prepareStage: (dir: string) => string;
|
|
17
|
+
export declare const stagedBuild: (dir: string, npm: Npm) => Promise<void>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, rmSync, symlinkSync, unlinkSync, } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { basename, join, resolve } from 'node:path';
|
|
5
|
+
import { getConfigDir } from '../../lib/fs/config.js';
|
|
6
|
+
import { buildScriptOf } from './package-build.js';
|
|
7
|
+
// The live tree the daemon runs is dist; the watcher writes only dist.next (the daemon copies it).
|
|
8
|
+
export const NEXT = 'dist.next';
|
|
9
|
+
const TSC = /^tsc(?:\s+-p\s+(\S+))?$/;
|
|
10
|
+
// The folder's own typescript, run as `node typescript/bin/tsc` (no .bin shim, none on Windows).
|
|
11
|
+
const tscOf = (dir) => {
|
|
12
|
+
try {
|
|
13
|
+
return createRequire(join(dir, 'package.json')).resolve('typescript/bin/tsc');
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const upModeOf = (dir) => {
|
|
20
|
+
const script = buildScriptOf(dir);
|
|
21
|
+
const [head = '', ...tail] = (script ?? '').split('&&');
|
|
22
|
+
const match = TSC.exec(head.trim());
|
|
23
|
+
const tsc = match ? tscOf(dir) : null;
|
|
24
|
+
if (!match || !tsc)
|
|
25
|
+
return { kind: 'stage', script };
|
|
26
|
+
const rest = tail.join('&&').trim();
|
|
27
|
+
return { kind: 'tsc', tsc, config: match[1] ?? 'tsconfig.json', rest: rest || null };
|
|
28
|
+
};
|
|
29
|
+
// dist.next starts as dist, so what tsc does not write (the manifest, dist/ui) stays in it.
|
|
30
|
+
export const seedNext = (dir) => {
|
|
31
|
+
mkdirSync(join(dir, NEXT), { recursive: true });
|
|
32
|
+
if (existsSync(join(dir, 'dist')))
|
|
33
|
+
cpSync(join(dir, 'dist'), join(dir, NEXT), { recursive: true, force: true });
|
|
34
|
+
};
|
|
35
|
+
// The stage is the config folder's cache, one per working copy: never inside the folder.
|
|
36
|
+
export const stageOf = (dir) => {
|
|
37
|
+
const hash = createHash('sha256').update(resolve(dir)).digest('hex').slice(0, 12);
|
|
38
|
+
return join(getConfigDir(), 'cache', 'up-stage', `${basename(resolve(dir))}-${hash}`);
|
|
39
|
+
};
|
|
40
|
+
const NOT_STAGED = new Set(['node_modules', '.agentage', '.git', 'coverage']);
|
|
41
|
+
const staged = (name) => !NOT_STAGED.has(name) && !name.startsWith('dist') && !name.startsWith('.env');
|
|
42
|
+
// The link goes first, so the remove never walks into the folder's own node_modules.
|
|
43
|
+
export const removeStage = (dir) => {
|
|
44
|
+
const modules = join(stageOf(dir), 'node_modules');
|
|
45
|
+
if (lstatSync(modules, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
46
|
+
unlinkSync(modules);
|
|
47
|
+
rmSync(stageOf(dir), { recursive: true, force: true });
|
|
48
|
+
};
|
|
49
|
+
// A copy with node_modules linked, no .env*, coverage, .git or dist*: never the live dist.
|
|
50
|
+
export const prepareStage = (dir) => {
|
|
51
|
+
const stage = stageOf(dir);
|
|
52
|
+
removeStage(dir);
|
|
53
|
+
mkdirSync(stage, { recursive: true });
|
|
54
|
+
for (const name of readdirSync(dir).filter(staged))
|
|
55
|
+
cpSync(join(dir, name), join(stage, name), { recursive: true });
|
|
56
|
+
const modules = join(dir, 'node_modules');
|
|
57
|
+
if (existsSync(modules))
|
|
58
|
+
symlinkSync(modules, join(stage, 'node_modules'), 'junction');
|
|
59
|
+
return stage;
|
|
60
|
+
};
|
|
61
|
+
// One build of the current src/ in the stage; its dist goes over dist.next (never the live dist).
|
|
62
|
+
export const stagedBuild = async (dir, npm) => {
|
|
63
|
+
const stage = existsSync(stageOf(dir)) ? stageOf(dir) : prepareStage(dir);
|
|
64
|
+
rmSync(join(stage, 'src'), { recursive: true, force: true });
|
|
65
|
+
if (existsSync(join(dir, 'src')))
|
|
66
|
+
cpSync(join(dir, 'src'), join(stage, 'src'), { recursive: true });
|
|
67
|
+
rmSync(join(stage, 'dist'), { recursive: true, force: true });
|
|
68
|
+
await npm(stage, ['run', 'build']);
|
|
69
|
+
if (existsSync(join(stage, 'dist')))
|
|
70
|
+
cpSync(join(stage, 'dist'), join(dir, NEXT), { recursive: true, force: true });
|
|
71
|
+
};
|
|
@@ -16,20 +16,21 @@ export const issuerUrl = (value) => {
|
|
|
16
16
|
};
|
|
17
17
|
const UP_HELP = `
|
|
18
18
|
With no Docker (the default): builds the package in --dir (default: the current folder) as
|
|
19
|
-
extension build does, prints what check refuses without stopping,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
extension build does, prints what check refuses without stopping, adds the folder to the daemon
|
|
20
|
+
(as extension install <folder> does; the daemon starts when none runs) and prints its URL on
|
|
21
|
+
127.0.0.1:4243. Then it watches src/: each change is built into dist.next/ (never the live dist/)
|
|
22
|
+
and the daemon reloads that one extension; one line per reload says reloaded or why it was
|
|
23
|
+
refused (the last good build runs). Ctrl-C stops the watch; extension down removes the row.
|
|
23
24
|
|
|
24
25
|
--docker runs the package the way a deployment runs it: the part images built with the release
|
|
25
26
|
recipe, the store with its migrations and seeds, a dev token issuer and a local gateway. Each
|
|
26
27
|
working copy is its own compose project; up refuses while another one holds localhost:4280 or
|
|
27
28
|
4281 and names it. Prints one line per step as the kit reports it. Exits 1 when a step fails.`;
|
|
28
29
|
const DOWN_HELP = `
|
|
29
|
-
Stops what agentage extension up started for the package in --dir, and nothing else: the
|
|
30
|
-
|
|
31
|
-
started there (its containers, network and the store's volume;
|
|
32
|
-
It says so when nothing runs. Exits 1 when that fails.`;
|
|
30
|
+
Stops what agentage extension up started for the package in --dir, and nothing else: the watch
|
|
31
|
+
of this folder and the daemon row up added (its data stays; a row up found there stays), and the
|
|
32
|
+
Docker stack up --docker started there (its containers, network and the store's volume;
|
|
33
|
+
--keep-data keeps the volume). It says so when nothing runs. Exits 1 when that fails.`;
|
|
33
34
|
const TOKEN_HELP = `
|
|
34
35
|
Prints a token from the dev issuer agentage extension up started for the package in --dir,
|
|
35
36
|
alone on stdout, for calling /api/v1/ and /mcp by hand or from tests. Only up trusts it. Exits 1
|
|
@@ -40,10 +41,10 @@ const DIR_TEXT = 'the extension package folder (default: the current folder)';
|
|
|
40
41
|
const addUp = (group, up) => {
|
|
41
42
|
addJson(group
|
|
42
43
|
.command('up')
|
|
43
|
-
.description('Run the working copy
|
|
44
|
+
.description('Run the working copy on the daemon and reload each change; --docker = on Docker')
|
|
44
45
|
.option(DIR, DIR_TEXT)
|
|
45
46
|
.option('--docker', 'the images, store, issuer and gateway on Docker')
|
|
46
|
-
.option('--local', 'the
|
|
47
|
+
.option('--local', 'deprecated: the old name of plain up (removed in the next minor)'))
|
|
47
48
|
.addHelpText('after', UP_HELP)
|
|
48
49
|
.action(up);
|
|
49
50
|
};
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare const UP_FROM = 4244;
|
|
1
|
+
import { type ProcessMark } from '../../lib/proc/start-time.js';
|
|
3
2
|
export interface UpRecord {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
up: ProcessMark;
|
|
4
|
+
nonce: string;
|
|
6
5
|
id: string;
|
|
7
|
-
|
|
6
|
+
added: boolean;
|
|
7
|
+
tsc?: ProcessMark;
|
|
8
8
|
}
|
|
9
9
|
export declare const recordPath: (dir: string) => string;
|
|
10
|
-
export declare const dataDirOf: (dir: string) => string;
|
|
11
10
|
export declare const readRecord: (dir: string) => UpRecord | null;
|
|
12
11
|
export declare const ignoreLocal: (dir: string) => void;
|
|
13
12
|
export declare const writeRecord: (dir: string, record: UpRecord) => void;
|
|
14
13
|
export declare const removeRecord: (dir: string) => void;
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
14
|
+
export declare const stopOrphan: (record: UpRecord | null) => void;
|
|
15
|
+
export declare const refuseRunning: (dir: string) => UpRecord | null;
|
|
16
|
+
export declare const selfMark: () => ProcessMark;
|
|
17
|
+
export declare const claimFolder: (dir: string, nonce: string, id: string) => Promise<UpRecord | null>;
|
|
18
|
+
export declare const rewriteRecord: (dir: string, record: UpRecord) => Promise<void>;
|
|
19
|
+
export declare const untilStopped: (dir: string, nonce: string, ended: Promise<string>, everyMs?: number) => Promise<string>;
|
|
20
20
|
export type LocalDown = 'stopped' | 'stale' | 'none';
|
|
21
|
-
export declare const stopLocal: (dir: string, timeoutMs?: number) => Promise<
|
|
21
|
+
export declare const stopLocal: (dir: string, timeoutMs?: number) => Promise<{
|
|
22
|
+
down: LocalDown;
|
|
23
|
+
record: UpRecord | null;
|
|
24
|
+
}>;
|