@phnx-labs/agents-cli 1.23.13 → 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 +38 -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/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,177 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as yaml from 'yaml';
|
|
4
|
-
import { exec } from 'child_process';
|
|
5
|
-
import { getDaemonConfigDir, getRuntimeStateDir } from './state.js';
|
|
6
|
-
import { atomicWriteFileSync } from './fs-atomic.js';
|
|
7
|
-
import { closeServerBounded } from './net-close.js';
|
|
8
|
-
import { readAndResolveBundleEnvSync } from './secrets-client.js';
|
|
9
|
-
import { startWebhookServer, createFileDeliveryStore, waitForListening } from './triggers/webhook.js';
|
|
10
|
-
import { buildFunnelUpCommand, FUNNEL_PORTS } from './funnel.js';
|
|
11
|
-
export const DEFAULT_WEBHOOK_PORT = 8787;
|
|
12
|
-
export const DEFAULT_WEBHOOK_RATE_LIMIT = 60;
|
|
13
|
-
export function getDaemonWebhooksConfigPath() {
|
|
14
|
-
return path.join(getDaemonConfigDir(), 'webhooks.yaml');
|
|
15
|
-
}
|
|
16
|
-
function coerceReceiver(item) {
|
|
17
|
-
if (!item || typeof item !== 'object')
|
|
18
|
-
return null;
|
|
19
|
-
const obj = item;
|
|
20
|
-
if (typeof obj.bundle !== 'string' || obj.bundle.length === 0)
|
|
21
|
-
return null;
|
|
22
|
-
const rc = { bundle: obj.bundle };
|
|
23
|
-
if (typeof obj.port === 'number' && Number.isInteger(obj.port) && obj.port > 0)
|
|
24
|
-
rc.port = obj.port;
|
|
25
|
-
if (typeof obj.rateLimit === 'number' && Number.isInteger(obj.rateLimit) && obj.rateLimit > 0)
|
|
26
|
-
rc.rateLimit = obj.rateLimit;
|
|
27
|
-
const funnel = obj.funnel;
|
|
28
|
-
if (funnel && typeof funnel === 'object' && FUNNEL_PORTS.includes(funnel.publicPort)) {
|
|
29
|
-
rc.funnel = { publicPort: funnel.publicPort };
|
|
30
|
-
}
|
|
31
|
-
return rc;
|
|
32
|
-
}
|
|
33
|
-
export function readDaemonWebhooksConfig() {
|
|
34
|
-
try {
|
|
35
|
-
const raw = fs.readFileSync(getDaemonWebhooksConfigPath(), 'utf-8');
|
|
36
|
-
const parsed = yaml.parse(raw);
|
|
37
|
-
const list = parsed && Array.isArray(parsed.receivers) ? parsed.receivers : [];
|
|
38
|
-
const receivers = list.map(coerceReceiver).filter((r) => r !== null);
|
|
39
|
-
return { receivers };
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return { receivers: [] };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export function writeDaemonWebhooksConfig(cfg) {
|
|
46
|
-
fs.mkdirSync(getDaemonConfigDir(), { recursive: true });
|
|
47
|
-
const out = yaml.stringify({ receivers: cfg.receivers }, { sortMapEntries: false });
|
|
48
|
-
atomicWriteFileSync(getDaemonWebhooksConfigPath(), out, 'utf-8');
|
|
49
|
-
}
|
|
50
|
-
export function hostedReceiverPort(receiver) {
|
|
51
|
-
return receiver.port ?? DEFAULT_WEBHOOK_PORT;
|
|
52
|
-
}
|
|
53
|
-
export function addHostedReceiver(receiver) {
|
|
54
|
-
const port = hostedReceiverPort(receiver);
|
|
55
|
-
const existing = readDaemonWebhooksConfig().receivers.filter((r) => hostedReceiverPort(r) !== port);
|
|
56
|
-
const next = { receivers: [...existing, receiver] };
|
|
57
|
-
writeDaemonWebhooksConfig(next);
|
|
58
|
-
return next;
|
|
59
|
-
}
|
|
60
|
-
export function removeHostedReceiver(port) {
|
|
61
|
-
const { receivers } = readDaemonWebhooksConfig();
|
|
62
|
-
const removed = receivers.find((r) => hostedReceiverPort(r) === port);
|
|
63
|
-
if (!removed)
|
|
64
|
-
return null;
|
|
65
|
-
writeDaemonWebhooksConfig({ receivers: receivers.filter((r) => hostedReceiverPort(r) !== port) });
|
|
66
|
-
return removed;
|
|
67
|
-
}
|
|
68
|
-
export function resolveReceiverSecrets(bundle) {
|
|
69
|
-
// Daemon reads are broker-only; missing signing secrets fail before any public bind.
|
|
70
|
-
const { env } = readAndResolveBundleEnvSync(bundle, { caller: 'daemon webhook-receiver', agentOnly: true });
|
|
71
|
-
const secrets = {};
|
|
72
|
-
if (env.GITHUB_WEBHOOK_SECRET)
|
|
73
|
-
secrets.github = env.GITHUB_WEBHOOK_SECRET;
|
|
74
|
-
if (env.LINEAR_WEBHOOK_SECRET)
|
|
75
|
-
secrets.linear = env.LINEAR_WEBHOOK_SECRET;
|
|
76
|
-
if (env.SLACK_SIGNING_SECRET)
|
|
77
|
-
secrets.slack = env.SLACK_SIGNING_SECRET;
|
|
78
|
-
if (!secrets.github && !secrets.linear && !secrets.slack) {
|
|
79
|
-
throw new Error(`bundle '${bundle}' has none of GITHUB_WEBHOOK_SECRET, LINEAR_WEBHOOK_SECRET, or SLACK_SIGNING_SECRET`);
|
|
80
|
-
}
|
|
81
|
-
return secrets;
|
|
82
|
-
}
|
|
83
|
-
function reconcileFunnel(publicPort, localPort, log) {
|
|
84
|
-
let command;
|
|
85
|
-
try {
|
|
86
|
-
command = buildFunnelUpCommand(publicPort, localPort);
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
log('WARN', `webhook funnel skipped (port ${publicPort}): ${err.message}`);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
exec(command, (err) => {
|
|
93
|
-
if (err) {
|
|
94
|
-
log('WARN', `webhook funnel reconcile failed (public ${publicPort} -> localhost:${localPort}); binding localhost only: ${err.message}`);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
log('INFO', `webhook funnel up: public ${publicPort} -> localhost:${localPort}`);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Start every receiver declared in `webhooks.yaml`. A receiver that cannot start
|
|
103
|
-
* — an unreadable secret (locked bundle, no webhook secret) or a failed bind
|
|
104
|
-
* (the port is already taken by a foreground `agents webhooks serve`, another
|
|
105
|
-
* daemon, or anything else) — is skipped with a loud WARN and does NOT take the
|
|
106
|
-
* others, or the daemon, down. Returns a handle that stops them all.
|
|
107
|
-
*
|
|
108
|
-
* This is async because a bind failure is only observable asynchronously:
|
|
109
|
-
* `server.listen()` surfaces EADDRINUSE as an `'error'` event, so a `try/catch`
|
|
110
|
-
* around the start call never sees it and the event reaches the process-level
|
|
111
|
-
* `uncaughtException` handler (`index.ts`), which exits 1 for the supervisor to
|
|
112
|
-
* restart — a crash loop that would take the scheduler, browser IPC,
|
|
113
|
-
* and self-heal down with it. `waitForListening` is what turns that into one
|
|
114
|
-
* skipped receiver.
|
|
115
|
-
*/
|
|
116
|
-
export async function startHostedWebhookReceivers(opts) {
|
|
117
|
-
// Receiver config is per-box; one failed bind closes its partial server without taking siblings down.
|
|
118
|
-
const { log } = opts;
|
|
119
|
-
const resolveSecrets = opts.resolveSecrets ?? resolveReceiverSecrets;
|
|
120
|
-
const { receivers } = readDaemonWebhooksConfig();
|
|
121
|
-
const servers = [];
|
|
122
|
-
for (const receiver of receivers) {
|
|
123
|
-
const port = receiver.port ?? DEFAULT_WEBHOOK_PORT;
|
|
124
|
-
let secrets;
|
|
125
|
-
try {
|
|
126
|
-
secrets = resolveSecrets(receiver.bundle);
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
log('WARN', `webhook receiver on :${port} skipped: ${err.message}`);
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
let server = null;
|
|
133
|
-
try {
|
|
134
|
-
server = startWebhookServer({
|
|
135
|
-
host: '127.0.0.1',
|
|
136
|
-
port,
|
|
137
|
-
secrets,
|
|
138
|
-
rateLimitPerMinute: receiver.rateLimit ?? DEFAULT_WEBHOOK_RATE_LIMIT,
|
|
139
|
-
deliveryStore: createFileDeliveryStore(path.join(getRuntimeStateDir(), 'webhook', `deliveries-${port}.json`)),
|
|
140
|
-
onMatch: (webhook, matchedJobNames, matchedHandlerNames) => {
|
|
141
|
-
const parts = [];
|
|
142
|
-
if (matchedJobNames.length)
|
|
143
|
-
parts.push(`routines ${matchedJobNames.join(', ')}`);
|
|
144
|
-
if (matchedHandlerNames.length)
|
|
145
|
-
parts.push(`handlers ${matchedHandlerNames.join(', ')}`);
|
|
146
|
-
log('INFO', `webhook ${webhook.source}:${webhook.event} ${parts.length ? `fired ${parts.join('; ')}` : 'no match'}`);
|
|
147
|
-
},
|
|
148
|
-
onDeliveryError: (webhook, err) => {
|
|
149
|
-
log('WARN', `webhook ${webhook.source}:${webhook.event} dispatch failed after ack: ${err.message}`);
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
const sockets = new Set();
|
|
153
|
-
server.on('connection', (socket) => {
|
|
154
|
-
sockets.add(socket);
|
|
155
|
-
socket.once('close', () => sockets.delete(socket));
|
|
156
|
-
});
|
|
157
|
-
await waitForListening(server);
|
|
158
|
-
servers.push({ server, sockets });
|
|
159
|
-
log('INFO', `webhook receiver bound on 127.0.0.1:${port} (bundle ${receiver.bundle})`);
|
|
160
|
-
if (receiver.funnel)
|
|
161
|
-
reconcileFunnel(receiver.funnel.publicPort, port, log);
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
server?.close(() => { });
|
|
165
|
-
log('WARN', `webhook receiver on :${port} failed to bind: ${err.message}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
count: servers.length,
|
|
170
|
-
close: () => Promise.all(servers.map(async ({ server, sockets }) => {
|
|
171
|
-
const closing = closeServerBounded(server);
|
|
172
|
-
for (const socket of sockets)
|
|
173
|
-
socket.destroy();
|
|
174
|
-
await closing;
|
|
175
|
-
})).then(() => undefined),
|
|
176
|
-
};
|
|
177
|
-
}
|
package/dist/lib/funnel.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const FUNNEL_PORTS: readonly [443, 8443, 10000];
|
|
2
|
-
export type FunnelPort = typeof FUNNEL_PORTS[number];
|
|
3
|
-
export declare function parseFunnelPort(value: string | number): FunnelPort;
|
|
4
|
-
export declare function buildFunnelStatusCommand(): string;
|
|
5
|
-
export declare function buildFunnelDownCommand(publicPort: FunnelPort): string;
|
|
6
|
-
export declare function buildFunnelUpCommand(publicPort: FunnelPort, localPort: number): string;
|
package/dist/lib/funnel.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { shellQuote } from './ssh-exec.js';
|
|
2
|
-
export const FUNNEL_PORTS = [443, 8443, 10000];
|
|
3
|
-
export function parseFunnelPort(value) {
|
|
4
|
-
const port = typeof value === 'number' ? value : Number.parseInt(value, 10);
|
|
5
|
-
if (FUNNEL_PORTS.includes(port))
|
|
6
|
-
return port;
|
|
7
|
-
throw new Error(`Tailscale Funnel public port must be one of: ${FUNNEL_PORTS.join(', ')}`);
|
|
8
|
-
}
|
|
9
|
-
export function buildFunnelStatusCommand() {
|
|
10
|
-
return 'tailscale funnel status';
|
|
11
|
-
}
|
|
12
|
-
export function buildFunnelDownCommand(publicPort) {
|
|
13
|
-
return [
|
|
14
|
-
'tailscale',
|
|
15
|
-
'funnel',
|
|
16
|
-
`--https=${publicPort}`,
|
|
17
|
-
'off',
|
|
18
|
-
].map(shellQuote).join(' ');
|
|
19
|
-
}
|
|
20
|
-
export function buildFunnelUpCommand(publicPort, localPort) {
|
|
21
|
-
if (!Number.isInteger(localPort) || localPort <= 0 || localPort > 65535) {
|
|
22
|
-
throw new Error('Local port must be between 1 and 65535');
|
|
23
|
-
}
|
|
24
|
-
return [
|
|
25
|
-
'tailscale',
|
|
26
|
-
'funnel',
|
|
27
|
-
'--bg',
|
|
28
|
-
`--https=${publicPort}`,
|
|
29
|
-
`http://localhost:${localPort}`,
|
|
30
|
-
].map(shellQuote).join(' ');
|
|
31
|
-
}
|
package/dist/lib/net-close.d.ts
DELETED
package/dist/lib/net-close.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const SERVER_CLOSE_TIMEOUT_MS = 5000;
|
|
2
|
-
export function closeServerBounded(server, timeoutMs = SERVER_CLOSE_TIMEOUT_MS) {
|
|
3
|
-
return new Promise((resolve) => {
|
|
4
|
-
let settled = false;
|
|
5
|
-
const finish = () => {
|
|
6
|
-
if (settled)
|
|
7
|
-
return;
|
|
8
|
-
settled = true;
|
|
9
|
-
clearTimeout(timer);
|
|
10
|
-
resolve();
|
|
11
|
-
};
|
|
12
|
-
const timer = setTimeout(finish, timeoutMs);
|
|
13
|
-
try {
|
|
14
|
-
server.close(() => finish());
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
finish();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const PORTABLE_HARNESSES: readonly ["claude", "codex", "opencode"];
|
|
2
|
-
type PortableHarness = (typeof PORTABLE_HARNESSES)[number];
|
|
3
|
-
export declare class MaterializeGuardError extends Error {
|
|
4
|
-
constructor(message: string);
|
|
5
|
-
}
|
|
6
|
-
export declare function assertPortableHarness(harness: string): PortableHarness;
|
|
7
|
-
export declare function assertExactHarnessVersion(version: string): string;
|
|
8
|
-
export declare function resolveOutputHome(raw: string, cwd?: string, home?: string): string;
|
|
9
|
-
export {};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as os from 'os';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { assertWithin, realpathExistingPrefix } from '../paths.js';
|
|
5
|
-
import { VERSION_RE } from '../agent-spec/primitives.js';
|
|
6
|
-
export const PORTABLE_HARNESSES = ['claude', 'codex', 'opencode'];
|
|
7
|
-
function isPortableHarness(value) {
|
|
8
|
-
return PORTABLE_HARNESSES.includes(value);
|
|
9
|
-
}
|
|
10
|
-
export class MaterializeGuardError extends Error {
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = 'MaterializeGuardError';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export function assertPortableHarness(harness) {
|
|
17
|
-
if (!isPortableHarness(harness)) {
|
|
18
|
-
throw new MaterializeGuardError(`Unsupported capability: '${harness}' is not a portable-agent harness (${PORTABLE_HARNESSES.join(', ')}).`);
|
|
19
|
-
}
|
|
20
|
-
return harness;
|
|
21
|
-
}
|
|
22
|
-
export function assertExactHarnessVersion(version) {
|
|
23
|
-
if (!version || version === 'latest' || !VERSION_RE.test(version)) {
|
|
24
|
-
throw new MaterializeGuardError(`Invalid harness version '${version}'. Pass an exact harness version (not @latest).`);
|
|
25
|
-
}
|
|
26
|
-
return version;
|
|
27
|
-
}
|
|
28
|
-
function outputHomeHasDotDot(raw) {
|
|
29
|
-
return raw.split(/[\\/]/).includes('..');
|
|
30
|
-
}
|
|
31
|
-
function danglingLinkChainTarget(p) {
|
|
32
|
-
let current = path.resolve(p);
|
|
33
|
-
let followed = false;
|
|
34
|
-
for (let hops = 0; hops < 40; hops++) {
|
|
35
|
-
let dest;
|
|
36
|
-
try {
|
|
37
|
-
dest = fs.readlinkSync(current);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return followed && !fs.existsSync(current) ? current : null;
|
|
41
|
-
}
|
|
42
|
-
followed = true;
|
|
43
|
-
current = path.resolve(path.dirname(current), dest);
|
|
44
|
-
}
|
|
45
|
-
return current;
|
|
46
|
-
}
|
|
47
|
-
function assertNoDanglingLiveHome(realHome) {
|
|
48
|
-
for (const name of PORTABLE_HARNESSES) {
|
|
49
|
-
if (danglingLinkChainTarget(path.join(realHome, `.${name}`)) !== null) {
|
|
50
|
-
throw new MaterializeGuardError(`Path escape: the live .${name} home is a dangling symlink; refusing every output home until it is repaired ` +
|
|
51
|
-
`(the materializer's mkdir -p would follow the link and re-create your live .${name} at its absent target)`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function liveHarnessHomes(realHome) {
|
|
56
|
-
return PORTABLE_HARNESSES.map((name) => ({
|
|
57
|
-
harness: name,
|
|
58
|
-
live: realpathExistingPrefix(path.join(realHome, `.${name}`)),
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
export function resolveOutputHome(raw, cwd = process.cwd(), home = os.homedir()) {
|
|
62
|
-
if (!raw || raw.includes('\0')) {
|
|
63
|
-
throw new MaterializeGuardError('Path escape: output home is empty or contains a null byte');
|
|
64
|
-
}
|
|
65
|
-
if (outputHomeHasDotDot(raw)) {
|
|
66
|
-
throw new MaterializeGuardError(`Path escape: ${raw}`);
|
|
67
|
-
}
|
|
68
|
-
const resolved = path.resolve(cwd, raw);
|
|
69
|
-
if (!path.isAbsolute(raw)) {
|
|
70
|
-
try {
|
|
71
|
-
assertWithin(cwd, resolved);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
throw new MaterializeGuardError(`Path escape: ${raw}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const canonical = realpathExistingPrefix(resolved);
|
|
78
|
-
const realHome = realpathExistingPrefix(home);
|
|
79
|
-
assertNoDanglingLiveHome(realHome);
|
|
80
|
-
if (canonical === realHome) {
|
|
81
|
-
throw new MaterializeGuardError('Path escape: output home must not be the live home directory');
|
|
82
|
-
}
|
|
83
|
-
for (const { harness, live } of liveHarnessHomes(realHome)) {
|
|
84
|
-
if (canonical === live || canonical.startsWith(live + path.sep)) {
|
|
85
|
-
throw new MaterializeGuardError(`Path escape: output home must not target the live .${harness} directory`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return resolved;
|
|
89
|
-
}
|
package/dist/lib/registry.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { RegistryType, RegistryConfig, McpServerEntry, SkillEntry, RegistrySearchResult, ResolvedPackage } from './types.js';
|
|
2
|
-
export declare function validatedNpmSpec(spec: string): string;
|
|
3
|
-
export declare function validatedPyPISpec(spec: string): string;
|
|
4
|
-
export declare function getRegistries(type: RegistryType): Record<string, RegistryConfig>;
|
|
5
|
-
export declare function getEnabledRegistries(type: RegistryType): Array<{
|
|
6
|
-
name: string;
|
|
7
|
-
config: RegistryConfig;
|
|
8
|
-
}>;
|
|
9
|
-
export declare function setRegistry(type: RegistryType, name: string, config: Partial<RegistryConfig>): void;
|
|
10
|
-
export declare function removeRegistry(type: RegistryType, name: string): boolean;
|
|
11
|
-
export declare function searchMcpRegistries(query: string, options?: {
|
|
12
|
-
registry?: string;
|
|
13
|
-
limit?: number;
|
|
14
|
-
}): Promise<RegistrySearchResult[]>;
|
|
15
|
-
export declare function mcpEntryToInstallSpec(entry: McpServerEntry): {
|
|
16
|
-
command?: string;
|
|
17
|
-
url?: string;
|
|
18
|
-
transport: 'stdio' | 'http';
|
|
19
|
-
} | null;
|
|
20
|
-
export declare function getMcpServerInfo(serverName: string, registryName?: string): Promise<McpServerEntry | null>;
|
|
21
|
-
export interface SkillIndexEntry {
|
|
22
|
-
name: string;
|
|
23
|
-
description?: string;
|
|
24
|
-
source?: string;
|
|
25
|
-
identifier?: string;
|
|
26
|
-
trust_level?: string;
|
|
27
|
-
repo?: string;
|
|
28
|
-
path?: string;
|
|
29
|
-
tags?: string[];
|
|
30
|
-
author?: string;
|
|
31
|
-
installs?: number;
|
|
32
|
-
sha256?: string;
|
|
33
|
-
}
|
|
34
|
-
export interface SkillIndexDocument {
|
|
35
|
-
version?: number;
|
|
36
|
-
generated_at?: string;
|
|
37
|
-
skill_count?: number;
|
|
38
|
-
skills: SkillIndexEntry[];
|
|
39
|
-
}
|
|
40
|
-
export declare function normalizeSkillEntry(raw: SkillIndexEntry): SkillEntry;
|
|
41
|
-
export declare function searchSkillRegistries(query: string, options?: {
|
|
42
|
-
registry?: string;
|
|
43
|
-
limit?: number;
|
|
44
|
-
}): Promise<RegistrySearchResult[]>;
|
|
45
|
-
export declare function getSkillEntry(skillIdentifier: string, registryName?: string): Promise<SkillEntry | null>;
|
|
46
|
-
export declare function skillEntryToGitSource(entry: SkillEntry): string | null;
|
|
47
|
-
export declare function search(query: string, options?: {
|
|
48
|
-
type?: RegistryType;
|
|
49
|
-
registry?: string;
|
|
50
|
-
limit?: number;
|
|
51
|
-
}): Promise<RegistrySearchResult[]>;
|
|
52
|
-
export declare function parsePackageIdentifier(identifier: string): {
|
|
53
|
-
type: RegistryType | 'git' | 'plugin' | 'unknown';
|
|
54
|
-
name: string;
|
|
55
|
-
};
|
|
56
|
-
export declare function resolvePackage(identifier: string): Promise<ResolvedPackage | null>;
|
|
57
|
-
export declare function sha256OfFile(file: string): string;
|
|
58
|
-
export declare function parseOwnerRepoFromRemote(remoteUrl: string): string | null;
|
|
59
|
-
export declare function buildSkillIndex(repoPath: string, repoSlug: string, opts?: {
|
|
60
|
-
generatedAt?: string;
|
|
61
|
-
}): SkillIndexDocument;
|
|
62
|
-
export declare function verifySkillIntegrity(repoPath: string, entry: Pick<SkillEntry, 'name' | 'path' | 'sha256'>): {
|
|
63
|
-
ok: boolean;
|
|
64
|
-
error?: string;
|
|
65
|
-
};
|