@phnx-labs/agents-cli 1.23.12 → 1.23.14
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/CHANGELOG.md +42 -0
- package/README.md +30 -59
- package/dist/cli/command-registry.js +0 -24
- package/dist/commands/accounts.js +3 -3
- package/dist/commands/daemon.js +5 -147
- package/dist/commands/doctor.js +7 -0
- package/dist/commands/events-logs.d.ts +2 -0
- package/dist/commands/{logs.js → events-logs.js} +28 -127
- package/dist/commands/events.js +3 -1
- package/dist/commands/exec.d.ts +0 -1
- package/dist/commands/exec.js +3 -11
- package/dist/commands/feed.d.ts +1 -1
- package/dist/commands/feed.js +4 -7
- package/dist/commands/mcp.js +1 -1
- package/dist/commands/menubar.js +12 -226
- package/dist/commands/projects.js +1 -2
- package/dist/commands/{trash.d.ts → prune-trash.d.ts} +1 -1
- package/dist/commands/{trash.js → prune-trash.js} +8 -8
- package/dist/commands/prune.js +3 -1
- package/dist/commands/send.js +2 -5
- package/dist/commands/sessions.js +1 -1
- package/dist/commands/setup.js +1 -1
- package/dist/commands/ssh.js +2 -2
- package/dist/commands/utils.d.ts +1 -5
- package/dist/commands/utils.js +1 -7
- package/dist/lib/agent-spec/agents.d.ts +0 -2
- package/dist/lib/agent-spec/agents.js +0 -12
- package/dist/lib/agent-spec/index.d.ts +0 -4
- package/dist/lib/agent-spec/index.js +0 -4
- package/dist/lib/commands.d.ts +1 -5
- package/dist/lib/commands.js +2 -69
- package/dist/lib/comms-render.d.ts +0 -7
- package/dist/lib/comms-render.js +0 -41
- package/dist/lib/config-keys.d.ts +1 -1
- package/dist/lib/config-keys.js +8 -0
- package/dist/lib/daemon/daemon.js +1 -6
- package/dist/lib/daemon-services.d.ts +1 -1
- package/dist/lib/daemon-services.js +0 -5
- package/dist/lib/device-config.d.ts +2 -0
- package/dist/lib/device-config.js +81 -8
- package/dist/lib/devices/doctor-findings.d.ts +6 -1
- package/dist/lib/devices/doctor-findings.js +34 -1
- package/dist/lib/git.d.ts +1 -0
- package/dist/lib/git.js +5 -0
- package/dist/lib/hooks/install.d.ts +0 -7
- package/dist/lib/hooks/install.js +0 -55
- package/dist/lib/hosts/passthrough.js +2 -4
- package/dist/lib/hosts/progress.js +2 -2
- package/dist/lib/hosts/remote-cmd.js +0 -1
- package/dist/lib/installations/migrate.d.ts +1 -0
- package/dist/lib/installations/migrate.js +18 -1
- package/dist/lib/installations/versions.js +2 -2
- package/dist/lib/loop.js +1 -1
- package/dist/lib/mailbox-target.d.ts +0 -31
- package/dist/lib/mailbox-target.js +0 -37
- package/dist/lib/mcp-lookup.d.ts +7 -0
- package/dist/lib/mcp-lookup.js +71 -0
- package/dist/lib/mcp.d.ts +0 -8
- package/dist/lib/mcp.js +0 -47
- package/dist/lib/menubar/install-menubar.d.ts +0 -15
- package/dist/lib/menubar/install-menubar.js +24 -118
- package/dist/lib/menubar/resolve-version.d.ts +9 -10
- package/dist/lib/menubar/resolve-version.js +70 -30
- package/dist/lib/paths.d.ts +0 -1
- package/dist/lib/paths.js +0 -18
- package/dist/lib/plugins/skills.d.ts +0 -10
- package/dist/lib/plugins/skills.js +2 -165
- package/dist/lib/project-pull.js +1 -2
- package/dist/lib/resources.d.ts +1 -1
- package/dist/lib/routines-project.js +1 -1
- package/dist/lib/session/local-tmux-attach.js +2 -2
- package/dist/lib/startup/command-registry.js +20 -7
- package/dist/lib/teams/agents.js +1 -1
- package/dist/lib/triggers/webhook.d.ts +2 -59
- package/dist/lib/triggers/webhook.js +2 -422
- package/package.json +2 -1
- package/dist/commands/funnel.d.ts +0 -2
- package/dist/commands/funnel.js +0 -77
- package/dist/commands/logs.d.ts +0 -2
- package/dist/commands/mailboxes.d.ts +0 -2
- package/dist/commands/mailboxes.js +0 -400
- package/dist/commands/message.d.ts +0 -2
- package/dist/commands/message.js +0 -259
- package/dist/commands/packages-materialize.d.ts +0 -6
- package/dist/commands/packages-materialize.js +0 -90
- package/dist/commands/packages.d.ts +0 -5
- package/dist/commands/packages.js +0 -763
- package/dist/commands/route.d.ts +0 -2
- package/dist/commands/route.js +0 -259
- package/dist/commands/testdata/feed-hub.d.ts +0 -1
- package/dist/commands/testdata/feed-hub.js +0 -11
- package/dist/commands/tmux.d.ts +0 -7
- package/dist/commands/tmux.js +0 -529
- package/dist/commands/traces.d.ts +0 -2
- package/dist/commands/traces.js +0 -204
- package/dist/commands/webhook.d.ts +0 -5
- package/dist/commands/webhook.js +0 -105
- package/dist/lib/agent-spec/materialize.d.ts +0 -3
- package/dist/lib/agent-spec/materialize.js +0 -277
- package/dist/lib/agent-spec/package-resolve.d.ts +0 -4
- package/dist/lib/agent-spec/package-resolve.js +0 -231
- package/dist/lib/agent-spec/package-schema.d.ts +0 -3
- package/dist/lib/agent-spec/package-schema.js +0 -136
- package/dist/lib/agent-spec/package-types.d.ts +0 -94
- package/dist/lib/agent-spec/package-types.js +0 -10
- package/dist/lib/daemon/testdata/process-view-daemon.d.ts +0 -1
- package/dist/lib/daemon/testdata/process-view-daemon.js +0 -12
- package/dist/lib/daemon/testdata/process-view-start.d.ts +0 -1
- package/dist/lib/daemon/testdata/process-view-start.js +0 -41
- package/dist/lib/daemon/webhook-receiver-service.d.ts +0 -8
- package/dist/lib/daemon/webhook-receiver-service.js +0 -16
- package/dist/lib/daemon-webhooks.d.ts +0 -48
- package/dist/lib/daemon-webhooks.js +0 -177
- package/dist/lib/funnel.d.ts +0 -6
- package/dist/lib/funnel.js +0 -31
- package/dist/lib/net-close.d.ts +0 -2
- package/dist/lib/net-close.js +0 -20
- package/dist/lib/packages/output-home.d.ts +0 -9
- package/dist/lib/packages/output-home.js +0 -89
- package/dist/lib/registry.d.ts +0 -65
- package/dist/lib/registry.js +0 -432
- package/dist/lib/routers.d.ts +0 -25
- package/dist/lib/routers.js +0 -122
- package/dist/lib/run-trace-sync.d.ts +0 -7
- package/dist/lib/run-trace-sync.js +0 -35
- package/dist/lib/session/testdata/pid-registry-namespace.d.ts +0 -1
- package/dist/lib/session/testdata/pid-registry-namespace.js +0 -25
- package/dist/lib/session/testdata/process-view-namespace.d.ts +0 -1
- package/dist/lib/session/testdata/process-view-namespace.js +0 -56
- package/dist/lib/session/testdata/process-view-private.d.ts +0 -1
- package/dist/lib/session/testdata/process-view-private.js +0 -11
- package/dist/lib/testdata/daemon-health-writer.d.ts +0 -1
- package/dist/lib/testdata/daemon-health-writer.js +0 -8
- package/dist/lib/testdata/owner-notify-api.d.ts +0 -23
- package/dist/lib/testdata/owner-notify-api.js +0 -82
- package/dist/lib/testdata/refresh-coordinator-worker.d.ts +0 -1
- package/dist/lib/testdata/refresh-coordinator-worker.js +0 -23
- package/dist/lib/traces/backend.d.ts +0 -8
- package/dist/lib/traces/backend.js +0 -33
- package/dist/lib/traces/classify.d.ts +0 -40
- package/dist/lib/traces/classify.js +0 -70
- package/dist/lib/traces/config.d.ts +0 -2
- package/dist/lib/traces/config.js +0 -2
- package/dist/lib/traces/insights.d.ts +0 -30
- package/dist/lib/traces/insights.js +0 -198
- package/dist/lib/traces/phenotype.d.ts +0 -18
- package/dist/lib/traces/phenotype.js +0 -335
- package/dist/lib/traces/provision.d.ts +0 -16
- package/dist/lib/traces/provision.js +0 -25
- package/dist/lib/traces/schema2-build.d.ts +0 -28
- package/dist/lib/traces/schema2-build.js +0 -496
- package/dist/lib/traces/schema2-danger.d.ts +0 -7
- package/dist/lib/traces/schema2-danger.js +0 -123
- package/dist/lib/traces/schema2.d.ts +0 -139
- package/dist/lib/traces/schema2.js +0 -20
- package/dist/lib/traces/segments.d.ts +0 -73
- package/dist/lib/traces/segments.js +0 -236
- package/dist/lib/traces/sync.d.ts +0 -197
- package/dist/lib/traces/sync.js +0 -654
- package/dist/lib/traces/worker-template.d.ts +0 -1
- package/dist/lib/traces/worker-template.js +0 -292
- package/dist/lib/triggers/handlers.d.ts +0 -66
- package/dist/lib/triggers/handlers.js +0 -383
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import * as yaml from 'yaml';
|
|
5
|
-
import { assertWithin, isSafeSegmentName } from '../paths.js';
|
|
6
|
-
import { loadAgentPackageManifest } from './package-schema.js';
|
|
7
|
-
import { AgentPackageError } from './package-types.js';
|
|
8
|
-
function assertRealSourceWithin(abs, packageReal, label) {
|
|
9
|
-
let lst;
|
|
10
|
-
try {
|
|
11
|
-
lst = fs.lstatSync(abs);
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (lst.isSymbolicLink()) {
|
|
17
|
-
throw new AgentPackageError(`${label}: '${abs}' is a symlink; symlinked package sources are not allowed`, 'path-escape');
|
|
18
|
-
}
|
|
19
|
-
let real;
|
|
20
|
-
try {
|
|
21
|
-
real = fs.realpathSync(abs);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (real !== packageReal && !real.startsWith(packageReal + path.sep)) {
|
|
27
|
-
throw new AgentPackageError(`${label}: '${abs}' resolves outside the package directory`, 'path-escape');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function resolveWithin(containRoot, relPath, label, packageReal) {
|
|
31
|
-
const abs = path.resolve(containRoot, relPath);
|
|
32
|
-
try {
|
|
33
|
-
assertWithin(containRoot, abs);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
throw new AgentPackageError(`${label}: '${relPath}' escapes the package directory`, 'path-escape');
|
|
37
|
-
}
|
|
38
|
-
assertRealSourceWithin(abs, packageReal, label);
|
|
39
|
-
return abs;
|
|
40
|
-
}
|
|
41
|
-
function sha256OfBytes(data) {
|
|
42
|
-
return crypto.createHash('sha256').update(data).digest('hex');
|
|
43
|
-
}
|
|
44
|
-
function sha256OfDir(dir) {
|
|
45
|
-
const files = [];
|
|
46
|
-
const walk = (base) => {
|
|
47
|
-
for (const entry of fs.readdirSync(base, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
48
|
-
if (entry.isSymbolicLink())
|
|
49
|
-
continue;
|
|
50
|
-
const full = path.join(base, entry.name);
|
|
51
|
-
if (entry.isDirectory())
|
|
52
|
-
walk(full);
|
|
53
|
-
else if (entry.isFile())
|
|
54
|
-
files.push(full);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
walk(dir);
|
|
58
|
-
const hash = crypto.createHash('sha256');
|
|
59
|
-
for (const file of files) {
|
|
60
|
-
const rel = path.relative(dir, file).split(path.sep).join('/');
|
|
61
|
-
hash.update(rel).update('\0').update(fs.readFileSync(file)).update('\n');
|
|
62
|
-
}
|
|
63
|
-
return hash.digest('hex');
|
|
64
|
-
}
|
|
65
|
-
function requireFile(absPath, label) {
|
|
66
|
-
let stat;
|
|
67
|
-
try {
|
|
68
|
-
stat = fs.statSync(absPath);
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
throw new AgentPackageError(`${label}: no such file '${absPath}'`, 'invalid-resource');
|
|
72
|
-
}
|
|
73
|
-
if (!stat.isFile()) {
|
|
74
|
-
throw new AgentPackageError(`${label}: '${absPath}' is not a file`, 'invalid-resource');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function requireDir(absPath, label) {
|
|
78
|
-
let stat;
|
|
79
|
-
try {
|
|
80
|
-
stat = fs.statSync(absPath);
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
throw new AgentPackageError(`${label}: no such directory '${absPath}'`, 'invalid-resource');
|
|
84
|
-
}
|
|
85
|
-
if (!stat.isDirectory()) {
|
|
86
|
-
throw new AgentPackageError(`${label}: '${absPath}' is not a directory`, 'invalid-resource');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function parseYamlFile(absPath, label) {
|
|
90
|
-
let raw;
|
|
91
|
-
try {
|
|
92
|
-
raw = fs.readFileSync(absPath, 'utf-8');
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
throw new AgentPackageError(`${label}: cannot read '${absPath}' — ${err.message}`, 'invalid-resource');
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
return yaml.parse(raw);
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
throw new AgentPackageError(`${label}: malformed YAML in '${absPath}' — ${err.message}`, 'invalid-resource');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function resolveInstructions(packageDir, relPath, provenance, label, packageReal) {
|
|
105
|
-
const abs = resolveWithin(packageDir, relPath, label, packageReal);
|
|
106
|
-
requireFile(abs, label);
|
|
107
|
-
return { kind: 'instructions', name: 'instructions', sourcePath: abs, sha256: sha256OfBytes(fs.readFileSync(abs)), provenance };
|
|
108
|
-
}
|
|
109
|
-
function resolveDirResource(packageDir, relPath, kind, markerFile, provenance, label, packageReal) {
|
|
110
|
-
const abs = resolveWithin(packageDir, relPath, label, packageReal);
|
|
111
|
-
requireDir(abs, label);
|
|
112
|
-
requireFile(path.join(abs, markerFile), `${label} (missing ${markerFile})`);
|
|
113
|
-
return { kind, name: path.basename(abs), sourcePath: abs, sha256: sha256OfDir(abs), provenance };
|
|
114
|
-
}
|
|
115
|
-
function resolveMcpResource(packageDir, relPath, provenance, label, packageReal) {
|
|
116
|
-
const abs = resolveWithin(packageDir, relPath, label, packageReal);
|
|
117
|
-
requireFile(abs, label);
|
|
118
|
-
const server = parseYamlFile(abs, label);
|
|
119
|
-
if (!server || typeof server.name !== 'string' || server.name.length === 0) {
|
|
120
|
-
throw new AgentPackageError(`${label}: '${relPath}' must declare a 'name'`, 'invalid-resource');
|
|
121
|
-
}
|
|
122
|
-
if (server.transport !== 'stdio' && server.transport !== 'http' && server.transport !== 'sse') {
|
|
123
|
-
throw new AgentPackageError(`${label}: '${relPath}' has an invalid transport (${JSON.stringify(server.transport)})`, 'invalid-resource');
|
|
124
|
-
}
|
|
125
|
-
if (server.transport === 'stdio' && !server.command) {
|
|
126
|
-
throw new AgentPackageError(`${label}: '${relPath}' declares transport 'stdio' but no 'command'`, 'invalid-resource');
|
|
127
|
-
}
|
|
128
|
-
if ((server.transport === 'http' || server.transport === 'sse') && !server.url) {
|
|
129
|
-
throw new AgentPackageError(`${label}: '${relPath}' declares transport '${server.transport}' but no 'url'`, 'invalid-resource');
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
kind: 'mcp',
|
|
133
|
-
name: server.name,
|
|
134
|
-
sourcePath: abs,
|
|
135
|
-
sha256: sha256OfBytes(fs.readFileSync(abs)),
|
|
136
|
-
provenance,
|
|
137
|
-
mcp: server,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
function resolveHookResource(packageDir, relPath, provenance, label, packageReal) {
|
|
141
|
-
const abs = resolveWithin(packageDir, relPath, label, packageReal);
|
|
142
|
-
requireFile(abs, label);
|
|
143
|
-
const hook = parseYamlFile(abs, label);
|
|
144
|
-
if (!hook || typeof hook.name !== 'string' || hook.name.length === 0) {
|
|
145
|
-
throw new AgentPackageError(`${label}: '${relPath}' must declare a 'name'`, 'invalid-resource');
|
|
146
|
-
}
|
|
147
|
-
if (!isSafeSegmentName(hook.name)) {
|
|
148
|
-
throw new AgentPackageError(`${label}: hook name '${hook.name}' is not a safe single path segment`, 'invalid-resource');
|
|
149
|
-
}
|
|
150
|
-
if (typeof hook.script !== 'string' || hook.script.length === 0) {
|
|
151
|
-
throw new AgentPackageError(`${label}: '${relPath}' must declare a 'script'`, 'invalid-resource');
|
|
152
|
-
}
|
|
153
|
-
if (!Array.isArray(hook.events) || hook.events.length === 0 || hook.events.some((e) => typeof e !== 'string')) {
|
|
154
|
-
throw new AgentPackageError(`${label}: '${relPath}' must declare a non-empty 'events' list of strings`, 'invalid-resource');
|
|
155
|
-
}
|
|
156
|
-
const scriptPath = resolveWithin(path.dirname(abs), hook.script, label, packageReal);
|
|
157
|
-
requireFile(scriptPath, `${label} (hook script)`);
|
|
158
|
-
return {
|
|
159
|
-
kind: 'hooks',
|
|
160
|
-
name: hook.name,
|
|
161
|
-
sourcePath: abs,
|
|
162
|
-
sha256: sha256OfBytes(Buffer.concat([fs.readFileSync(abs), Buffer.from('\0'), fs.readFileSync(scriptPath)])),
|
|
163
|
-
provenance,
|
|
164
|
-
hook: { def: hook, scriptPath },
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function assertNoDuplicates(resources, scopeLabel) {
|
|
168
|
-
const seen = new Map();
|
|
169
|
-
for (const r of resources) {
|
|
170
|
-
const key = `${r.kind}:${r.name}`;
|
|
171
|
-
const prior = seen.get(key);
|
|
172
|
-
if (prior) {
|
|
173
|
-
throw new AgentPackageError(`${scopeLabel}: duplicate ${r.kind} '${r.name}' declared by both '${prior.sourcePath}' and '${r.sourcePath}'`, 'duplicate-resource');
|
|
174
|
-
}
|
|
175
|
-
seen.set(key, r);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
function resolveScope(packageDir, paths, provenance, scopeLabel, packageReal) {
|
|
179
|
-
const resources = [];
|
|
180
|
-
if (paths.instructions)
|
|
181
|
-
resources.push(resolveInstructions(packageDir, paths.instructions, provenance, scopeLabel, packageReal));
|
|
182
|
-
for (const p of paths.skills)
|
|
183
|
-
resources.push(resolveDirResource(packageDir, p, 'skills', 'SKILL.md', provenance, scopeLabel, packageReal));
|
|
184
|
-
for (const p of paths.subagents)
|
|
185
|
-
resources.push(resolveDirResource(packageDir, p, 'subagents', 'AGENT.md', provenance, scopeLabel, packageReal));
|
|
186
|
-
for (const p of paths.mcp)
|
|
187
|
-
resources.push(resolveMcpResource(packageDir, p, provenance, scopeLabel, packageReal));
|
|
188
|
-
for (const p of paths.hooks)
|
|
189
|
-
resources.push(resolveHookResource(packageDir, p, provenance, scopeLabel, packageReal));
|
|
190
|
-
resources.sort((a, b) => (a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind.localeCompare(b.kind)));
|
|
191
|
-
assertNoDuplicates(resources, scopeLabel);
|
|
192
|
-
return resources;
|
|
193
|
-
}
|
|
194
|
-
function computeDigest(portable, overlays) {
|
|
195
|
-
const hash = crypto.createHash('sha256');
|
|
196
|
-
const record = (label, resources) => {
|
|
197
|
-
for (const r of resources)
|
|
198
|
-
hash.update(`${label}\0${r.kind}\0${r.name}\0${r.sha256}\n`);
|
|
199
|
-
};
|
|
200
|
-
record('portable', portable);
|
|
201
|
-
for (const agent of Object.keys(overlays).sort())
|
|
202
|
-
record(`overlay:${agent}`, overlays[agent] ?? []);
|
|
203
|
-
return hash.digest('hex');
|
|
204
|
-
}
|
|
205
|
-
export function resolveAgentPackage(packageDir) {
|
|
206
|
-
const manifest = loadAgentPackageManifest(packageDir);
|
|
207
|
-
const ex = manifest.execution;
|
|
208
|
-
const packageReal = fs.realpathSync(path.resolve(packageDir));
|
|
209
|
-
const portable = resolveScope(packageDir, { instructions: ex.instructions, skills: ex.skills, subagents: ex.subagents, mcp: ex.mcp, hooks: ex.hooks }, 'portable', 'execution', packageReal);
|
|
210
|
-
const overlays = {};
|
|
211
|
-
for (const [agent, overlay] of Object.entries(ex.harnessOverlays)) {
|
|
212
|
-
overlays[agent] = resolveScope(packageDir, { instructions: overlay.instructions, skills: overlay.skills ?? [], subagents: overlay.subagents ?? [], mcp: overlay.mcp ?? [], hooks: overlay.hooks ?? [] }, 'overlay', `execution.harness_overlays.${agent}`, packageReal);
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
manifest,
|
|
216
|
-
packageDir: path.resolve(packageDir),
|
|
217
|
-
digest: computeDigest(portable, overlays),
|
|
218
|
-
portable,
|
|
219
|
-
overlays,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
export function effectiveResources(resolved, harness) {
|
|
223
|
-
const overlay = resolved.overlays[harness] ?? [];
|
|
224
|
-
const overlayKeys = new Set(overlay.map((r) => `${r.kind}:${r.name}`));
|
|
225
|
-
const merged = [
|
|
226
|
-
...resolved.portable.filter((r) => !overlayKeys.has(`${r.kind}:${r.name}`)),
|
|
227
|
-
...overlay,
|
|
228
|
-
];
|
|
229
|
-
merged.sort((a, b) => (a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind.localeCompare(b.kind)));
|
|
230
|
-
return merged;
|
|
231
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as yaml from 'yaml';
|
|
4
|
-
import { ALL_AGENT_IDS } from './agents.js';
|
|
5
|
-
import { AgentPackageError } from './package-types.js';
|
|
6
|
-
const AGENT_ID_SET = new Set(ALL_AGENT_IDS);
|
|
7
|
-
function isAgentId(value) {
|
|
8
|
-
return typeof value === 'string' && AGENT_ID_SET.has(value);
|
|
9
|
-
}
|
|
10
|
-
function fail(message, details) {
|
|
11
|
-
throw new AgentPackageError(message, 'invalid-manifest', details);
|
|
12
|
-
}
|
|
13
|
-
function stringArray(value, field) {
|
|
14
|
-
if (value === undefined || value === null)
|
|
15
|
-
return [];
|
|
16
|
-
if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
|
|
17
|
-
fail(`agent.yaml: '${field}' must be a list of strings`);
|
|
18
|
-
}
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
function parseHarnessOverlay(raw, agent) {
|
|
22
|
-
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
23
|
-
fail(`agent.yaml: execution.harness_overlays.${agent} must be a mapping`);
|
|
24
|
-
}
|
|
25
|
-
const r = raw;
|
|
26
|
-
if (r.instructions !== undefined && typeof r.instructions !== 'string') {
|
|
27
|
-
fail(`agent.yaml: execution.harness_overlays.${agent}.instructions must be a string`);
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
instructions: r.instructions,
|
|
31
|
-
skills: stringArray(r.skills, `execution.harness_overlays.${agent}.skills`),
|
|
32
|
-
subagents: stringArray(r.subagents, `execution.harness_overlays.${agent}.subagents`),
|
|
33
|
-
mcp: stringArray(r.mcp, `execution.harness_overlays.${agent}.mcp`),
|
|
34
|
-
hooks: stringArray(r.hooks, `execution.harness_overlays.${agent}.hooks`),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export function parseAgentPackageManifest(raw, sourceLabel) {
|
|
38
|
-
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
39
|
-
fail(`${sourceLabel}: expected a YAML mapping at the document root`);
|
|
40
|
-
}
|
|
41
|
-
const doc = raw;
|
|
42
|
-
if (doc.schema_version !== 3) {
|
|
43
|
-
fail(`${sourceLabel}: schema_version must be 3 (got ${JSON.stringify(doc.schema_version)}) — this resolver only understands schema v3 execution blocks`);
|
|
44
|
-
}
|
|
45
|
-
if ('http_tools' in doc) {
|
|
46
|
-
fail(`${sourceLabel}: 'http_tools' is forbidden at schema v3 — use execution.mcp instead`);
|
|
47
|
-
}
|
|
48
|
-
if (typeof doc.name !== 'string' || doc.name.length === 0) {
|
|
49
|
-
fail(`${sourceLabel}: 'name' is required and must be a non-empty string`);
|
|
50
|
-
}
|
|
51
|
-
if (typeof doc.slug !== 'string' || doc.slug.length === 0) {
|
|
52
|
-
fail(`${sourceLabel}: 'slug' is required and must be a non-empty string`);
|
|
53
|
-
}
|
|
54
|
-
if (doc.description !== undefined && typeof doc.description !== 'string') {
|
|
55
|
-
fail(`${sourceLabel}: 'description' must be a string`);
|
|
56
|
-
}
|
|
57
|
-
const execution = doc.execution;
|
|
58
|
-
if (execution === null || typeof execution !== 'object' || Array.isArray(execution)) {
|
|
59
|
-
fail(`${sourceLabel}: 'execution' block is required`);
|
|
60
|
-
}
|
|
61
|
-
const ex = execution;
|
|
62
|
-
const mode = ex.mode;
|
|
63
|
-
if (mode !== 'cloud' && mode !== 'local') {
|
|
64
|
-
fail(`${sourceLabel}: execution.mode must be 'cloud' or 'local' (got ${JSON.stringify(mode)})`);
|
|
65
|
-
}
|
|
66
|
-
const harnesses = ex.harnesses;
|
|
67
|
-
if (harnesses === null || typeof harnesses !== 'object' || Array.isArray(harnesses)) {
|
|
68
|
-
fail(`${sourceLabel}: execution.harnesses is required`);
|
|
69
|
-
}
|
|
70
|
-
const h = harnesses;
|
|
71
|
-
if (!isAgentId(h.default)) {
|
|
72
|
-
fail(`${sourceLabel}: execution.harnesses.default must name a known agent id (got ${JSON.stringify(h.default)})`);
|
|
73
|
-
}
|
|
74
|
-
const supportedRaw = stringArray(h.supported, 'execution.harnesses.supported');
|
|
75
|
-
if (supportedRaw.length === 0) {
|
|
76
|
-
fail(`${sourceLabel}: execution.harnesses.supported must list at least one agent id`);
|
|
77
|
-
}
|
|
78
|
-
const badIds = supportedRaw.filter((id) => !isAgentId(id));
|
|
79
|
-
if (badIds.length > 0) {
|
|
80
|
-
fail(`${sourceLabel}: execution.harnesses.supported names unknown agent id(s): ${badIds.join(', ')}`);
|
|
81
|
-
}
|
|
82
|
-
const supported = supportedRaw;
|
|
83
|
-
if (!supported.includes(h.default)) {
|
|
84
|
-
fail(`${sourceLabel}: execution.harnesses.default (${String(h.default)}) must also appear in execution.harnesses.supported`);
|
|
85
|
-
}
|
|
86
|
-
if (typeof ex.instructions !== 'string' || ex.instructions.length === 0) {
|
|
87
|
-
fail(`${sourceLabel}: execution.instructions is required and must be a non-empty relative path`);
|
|
88
|
-
}
|
|
89
|
-
const harnessOverlaysRaw = ex.harness_overlays;
|
|
90
|
-
const harnessOverlays = {};
|
|
91
|
-
if (harnessOverlaysRaw !== undefined) {
|
|
92
|
-
if (harnessOverlaysRaw === null || typeof harnessOverlaysRaw !== 'object' || Array.isArray(harnessOverlaysRaw)) {
|
|
93
|
-
fail(`${sourceLabel}: execution.harness_overlays must be a mapping`);
|
|
94
|
-
}
|
|
95
|
-
for (const [agent, overlay] of Object.entries(harnessOverlaysRaw)) {
|
|
96
|
-
if (!isAgentId(agent)) {
|
|
97
|
-
fail(`${sourceLabel}: execution.harness_overlays names unknown agent id: ${agent}`);
|
|
98
|
-
}
|
|
99
|
-
harnessOverlays[agent] = parseHarnessOverlay(overlay, agent);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
schemaVersion: 3,
|
|
104
|
-
name: doc.name,
|
|
105
|
-
slug: doc.slug,
|
|
106
|
-
description: doc.description,
|
|
107
|
-
execution: {
|
|
108
|
-
mode,
|
|
109
|
-
harnesses: { default: h.default, supported },
|
|
110
|
-
instructions: ex.instructions,
|
|
111
|
-
skills: stringArray(ex.skills, 'execution.skills'),
|
|
112
|
-
subagents: stringArray(ex.subagents, 'execution.subagents'),
|
|
113
|
-
mcp: stringArray(ex.mcp, 'execution.mcp'),
|
|
114
|
-
hooks: stringArray(ex.hooks, 'execution.hooks'),
|
|
115
|
-
harnessOverlays,
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
export function loadAgentPackageManifest(packageDir) {
|
|
120
|
-
const manifestPath = path.join(packageDir, 'agent.yaml');
|
|
121
|
-
let raw;
|
|
122
|
-
try {
|
|
123
|
-
raw = fs.readFileSync(manifestPath, 'utf-8');
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
throw new AgentPackageError(`agent.yaml not found in ${packageDir}`, 'invalid-manifest');
|
|
127
|
-
}
|
|
128
|
-
let doc;
|
|
129
|
-
try {
|
|
130
|
-
doc = yaml.parse(raw);
|
|
131
|
-
}
|
|
132
|
-
catch (err) {
|
|
133
|
-
throw new AgentPackageError(`${manifestPath}: malformed YAML — ${err.message}`, 'invalid-manifest');
|
|
134
|
-
}
|
|
135
|
-
return parseAgentPackageManifest(doc, manifestPath);
|
|
136
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { AgentId } from '../types.js';
|
|
2
|
-
export type PackageResourceKind = 'instructions' | 'skills' | 'subagents' | 'mcp' | 'hooks';
|
|
3
|
-
export type ResourceProvenance = 'portable' | 'overlay';
|
|
4
|
-
export declare class AgentPackageError extends Error {
|
|
5
|
-
readonly code: 'invalid-manifest' | 'invalid-resource' | 'duplicate-resource' | 'path-escape' | 'unsupported-harness' | 'unsupported-capability';
|
|
6
|
-
readonly details?: string[] | undefined;
|
|
7
|
-
constructor(message: string, code: 'invalid-manifest' | 'invalid-resource' | 'duplicate-resource' | 'path-escape' | 'unsupported-harness' | 'unsupported-capability', details?: string[] | undefined);
|
|
8
|
-
}
|
|
9
|
-
export interface PackageMcpServer {
|
|
10
|
-
name: string;
|
|
11
|
-
transport: 'stdio' | 'http' | 'sse';
|
|
12
|
-
command?: string;
|
|
13
|
-
args?: string[];
|
|
14
|
-
env?: Record<string, string>;
|
|
15
|
-
url?: string;
|
|
16
|
-
headers?: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
export interface PackageHook {
|
|
19
|
-
name: string;
|
|
20
|
-
script: string;
|
|
21
|
-
events: string[];
|
|
22
|
-
matcher?: string;
|
|
23
|
-
timeout?: number;
|
|
24
|
-
}
|
|
25
|
-
export interface PackageHarnessOverlay {
|
|
26
|
-
instructions?: string;
|
|
27
|
-
skills?: string[];
|
|
28
|
-
subagents?: string[];
|
|
29
|
-
mcp?: string[];
|
|
30
|
-
hooks?: string[];
|
|
31
|
-
}
|
|
32
|
-
export interface AgentPackageManifest {
|
|
33
|
-
schemaVersion: 3;
|
|
34
|
-
name: string;
|
|
35
|
-
slug: string;
|
|
36
|
-
description?: string;
|
|
37
|
-
execution: {
|
|
38
|
-
mode: 'cloud' | 'local';
|
|
39
|
-
harnesses: {
|
|
40
|
-
default: AgentId;
|
|
41
|
-
supported: AgentId[];
|
|
42
|
-
};
|
|
43
|
-
instructions: string;
|
|
44
|
-
skills: string[];
|
|
45
|
-
subagents: string[];
|
|
46
|
-
mcp: string[];
|
|
47
|
-
hooks: string[];
|
|
48
|
-
harnessOverlays: Partial<Record<AgentId, PackageHarnessOverlay>>;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export interface ResolvedResource {
|
|
52
|
-
kind: PackageResourceKind;
|
|
53
|
-
name: string;
|
|
54
|
-
sourcePath: string;
|
|
55
|
-
sha256: string;
|
|
56
|
-
provenance: ResourceProvenance;
|
|
57
|
-
mcp?: PackageMcpServer;
|
|
58
|
-
hook?: {
|
|
59
|
-
def: PackageHook;
|
|
60
|
-
scriptPath: string;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export interface ResolvedAgentPackage {
|
|
64
|
-
manifest: AgentPackageManifest;
|
|
65
|
-
packageDir: string;
|
|
66
|
-
digest: string;
|
|
67
|
-
portable: ResolvedResource[];
|
|
68
|
-
overlays: Partial<Record<AgentId, ResolvedResource[]>>;
|
|
69
|
-
}
|
|
70
|
-
export interface MaterializationReceiptEntry {
|
|
71
|
-
kind: PackageResourceKind;
|
|
72
|
-
name: string;
|
|
73
|
-
target: string;
|
|
74
|
-
sha256: string;
|
|
75
|
-
provenance: ResourceProvenance;
|
|
76
|
-
}
|
|
77
|
-
export interface MaterializationReceipt {
|
|
78
|
-
schemaVersion: 1;
|
|
79
|
-
agent: {
|
|
80
|
-
ref: string;
|
|
81
|
-
digest: string;
|
|
82
|
-
};
|
|
83
|
-
harness: {
|
|
84
|
-
id: AgentId;
|
|
85
|
-
version: string;
|
|
86
|
-
};
|
|
87
|
-
resources: MaterializationReceiptEntry[];
|
|
88
|
-
warnings: string[];
|
|
89
|
-
}
|
|
90
|
-
export interface MaterializeOptions {
|
|
91
|
-
harness: AgentId;
|
|
92
|
-
harnessVersion: string;
|
|
93
|
-
outputHome: string;
|
|
94
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import net from 'node:net';
|
|
5
|
-
import { spawn } from 'node:child_process';
|
|
6
|
-
import { serviceManagerRegistrationAllowed } from '../../service-manifest.js';
|
|
7
|
-
import { startDaemon, stopDaemon } from '../daemon.js';
|
|
8
|
-
import { getDaemonDir, getTerminalsDir, getCacheDir } from '../../state.js';
|
|
9
|
-
assert.equal(serviceManagerRegistrationAllowed().allowed, false, 'isolated fixture must never access the production service manager');
|
|
10
|
-
const cold = process.argv[3] === 'cold';
|
|
11
|
-
const child = cold ? spawn('bun', [process.argv[4], '__daemon-run'], { stdio: 'ignore', env: process.env }) : undefined;
|
|
12
|
-
const started = child ? { pid: child.pid, method: 'detached' } : startDaemon(process.argv[2]);
|
|
13
|
-
assert.equal(started.method, 'detached');
|
|
14
|
-
assert.ok(started.pid);
|
|
15
|
-
fs.writeFileSync(path.join(process.env.HOME, 'test-child.pid'), String(started.pid));
|
|
16
|
-
try {
|
|
17
|
-
if (!cold)
|
|
18
|
-
assert.ok(fs.existsSync(path.join(getDaemonDir(), 'health.json')), 'ordinary launcher publishes health before daemon starts');
|
|
19
|
-
const socket = path.join(getCacheDir(), 'helpers', 'feed', 'feed-stream.sock');
|
|
20
|
-
let ready = false;
|
|
21
|
-
for (let i = 0; i < 80 && !ready; i++) {
|
|
22
|
-
ready = await new Promise(resolve => {
|
|
23
|
-
const client = net.createConnection(socket);
|
|
24
|
-
const done = (value) => { client.destroy(); resolve(value); };
|
|
25
|
-
client.setTimeout(100, () => done(false));
|
|
26
|
-
client.once('connect', () => done(true));
|
|
27
|
-
client.once('error', () => done(false));
|
|
28
|
-
});
|
|
29
|
-
if (!ready)
|
|
30
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
31
|
-
}
|
|
32
|
-
assert.ok(ready, 'ordinary fresh-home daemon must serve its feed-stream hub socket');
|
|
33
|
-
assert.equal(fs.readFileSync(path.join(getDaemonDir(), 'daemon.pid'), 'utf8').trim(), String(started.pid));
|
|
34
|
-
const owner = JSON.parse(fs.readFileSync(path.join(getTerminalsDir(), 'process-view.json'), 'utf8'));
|
|
35
|
-
assert.equal(owner.pidNamespace, fs.readlinkSync('/proc/self/ns/pid'));
|
|
36
|
-
assert.equal(owner.bootId, fs.readFileSync('/proc/sys/kernel/random/boot_id', 'utf8').trim());
|
|
37
|
-
console.log(`${cold ? 'cold runDaemon' : 'ordinary startDaemon: health published'}; canonical socket ready; namespace owner verified`);
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
stopDaemon();
|
|
41
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DaemonServiceId } from '../daemon-services.js';
|
|
2
|
-
import { BaseDaemonService, type DaemonContext } from './service.js';
|
|
3
|
-
export declare class WebhookReceiverService extends BaseDaemonService {
|
|
4
|
-
readonly id: DaemonServiceId;
|
|
5
|
-
private receivers;
|
|
6
|
-
protected onStart(ctx: DaemonContext): Promise<void>;
|
|
7
|
-
protected onStop(): Promise<void>;
|
|
8
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { startHostedWebhookReceivers } from '../daemon-webhooks.js';
|
|
2
|
-
import { BaseDaemonService } from './service.js';
|
|
3
|
-
export class WebhookReceiverService extends BaseDaemonService {
|
|
4
|
-
id = 'webhook-receiver';
|
|
5
|
-
receivers = null;
|
|
6
|
-
async onStart(ctx) {
|
|
7
|
-
this.receivers = await startHostedWebhookReceivers({ log: ctx.log });
|
|
8
|
-
ctx.log('INFO', this.receivers.count > 0
|
|
9
|
-
? `Webhook receiver hosting ${this.receivers.count} receiver(s)`
|
|
10
|
-
: 'Webhook receiver service enabled; no receivers declared in daemon/webhooks.yaml');
|
|
11
|
-
}
|
|
12
|
-
async onStop() {
|
|
13
|
-
await this.receivers?.close();
|
|
14
|
-
this.receivers = null;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type WebhookSecrets } from './triggers/webhook.js';
|
|
2
|
-
import { type FunnelPort } from './funnel.js';
|
|
3
|
-
export declare const DEFAULT_WEBHOOK_PORT = 8787;
|
|
4
|
-
export declare const DEFAULT_WEBHOOK_RATE_LIMIT = 60;
|
|
5
|
-
export interface HostedReceiverFunnel {
|
|
6
|
-
publicPort: FunnelPort;
|
|
7
|
-
}
|
|
8
|
-
export interface HostedReceiverConfig {
|
|
9
|
-
bundle: string;
|
|
10
|
-
port?: number;
|
|
11
|
-
rateLimit?: number;
|
|
12
|
-
funnel?: HostedReceiverFunnel;
|
|
13
|
-
}
|
|
14
|
-
interface DaemonWebhooksConfig {
|
|
15
|
-
receivers: HostedReceiverConfig[];
|
|
16
|
-
}
|
|
17
|
-
export declare function getDaemonWebhooksConfigPath(): string;
|
|
18
|
-
export declare function readDaemonWebhooksConfig(): DaemonWebhooksConfig;
|
|
19
|
-
export declare function writeDaemonWebhooksConfig(cfg: DaemonWebhooksConfig): void;
|
|
20
|
-
export declare function hostedReceiverPort(receiver: HostedReceiverConfig): number;
|
|
21
|
-
export declare function addHostedReceiver(receiver: HostedReceiverConfig): DaemonWebhooksConfig;
|
|
22
|
-
export declare function removeHostedReceiver(port: number): HostedReceiverConfig | null;
|
|
23
|
-
export declare function resolveReceiverSecrets(bundle: string): WebhookSecrets;
|
|
24
|
-
export interface HostedWebhookReceivers {
|
|
25
|
-
count: number;
|
|
26
|
-
close(): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
type Logger = (level: string, message: string) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Start every receiver declared in `webhooks.yaml`. A receiver that cannot start
|
|
31
|
-
* — an unreadable secret (locked bundle, no webhook secret) or a failed bind
|
|
32
|
-
* (the port is already taken by a foreground `agents webhooks serve`, another
|
|
33
|
-
* daemon, or anything else) — is skipped with a loud WARN and does NOT take the
|
|
34
|
-
* others, or the daemon, down. Returns a handle that stops them all.
|
|
35
|
-
*
|
|
36
|
-
* This is async because a bind failure is only observable asynchronously:
|
|
37
|
-
* `server.listen()` surfaces EADDRINUSE as an `'error'` event, so a `try/catch`
|
|
38
|
-
* around the start call never sees it and the event reaches the process-level
|
|
39
|
-
* `uncaughtException` handler (`index.ts`), which exits 1 for the supervisor to
|
|
40
|
-
* restart — a crash loop that would take the scheduler, browser IPC,
|
|
41
|
-
* and self-heal down with it. `waitForListening` is what turns that into one
|
|
42
|
-
* skipped receiver.
|
|
43
|
-
*/
|
|
44
|
-
export declare function startHostedWebhookReceivers(opts: {
|
|
45
|
-
log: Logger;
|
|
46
|
-
resolveSecrets?: (bundle: string) => WebhookSecrets;
|
|
47
|
-
}): Promise<HostedWebhookReceivers>;
|
|
48
|
-
export {};
|