@bakers-build/addon-ports 0.5.1-next.856 → 0.5.1-next.858
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/claim-share.js +3 -3
- package/dist/src/config.js +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/lock.js +1 -1
- package/dist/src/preset.js +3 -2
- package/package.json +5 -5
- package/dist/src/inbox.d.ts +0 -35
- package/dist/src/inbox.js +0 -91
- package/dist/src/tunnel-result.d.ts +0 -6
- package/dist/src/tunnel-result.js +0 -41
package/dist/src/claim-share.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// BB-676 spec v5 — shared "bring up everything eligible" predicate AND I/O
|
|
2
|
-
// loop (`shareAll`, pass-6 review cleanup), used by both the `
|
|
3
|
-
// message and `bakers ports up` with no
|
|
4
|
-
// everything" entry points cannot drift apart.
|
|
2
|
+
// loop (`shareAll`, pass-6 review cleanup), used by both the `ports_up` tool
|
|
3
|
+
// (which the `tunnel` inbox message is bound to) and `bakers ports up` with no
|
|
4
|
+
// service key, so the two "share everything" entry points cannot drift apart.
|
|
5
5
|
/** Eligible = a healthy (or prepared-Drupal-passthrough) claim with a rule. */
|
|
6
6
|
export function eligible(service) {
|
|
7
7
|
return service.rules.length > 0;
|
package/dist/src/config.js
CHANGED
|
@@ -9,8 +9,8 @@ import { checkWith } from './service-config.js';
|
|
|
9
9
|
import { assertPortsTransport, InvalidTransportModuleError, } from './transport.js';
|
|
10
10
|
/**
|
|
11
11
|
* Resolution bases rooted at the running `bakers` HOST install, usable from
|
|
12
|
-
* both the CLI (which gets a `BbCommandHost`) and the
|
|
13
|
-
* does not: `oven start`/`once` dispatches
|
|
12
|
+
* both the CLI (which gets a `BbCommandHost`) and the conductor tools (which
|
|
13
|
+
* does not: `oven start`/`once` dispatches tool calls from inside
|
|
14
14
|
* the SAME long-running `bakers` process, never a subprocess). The three
|
|
15
15
|
* built-in transport packages are declared only on `bakers-cli/host/package.json`
|
|
16
16
|
* (never on `@bakers-build/addon-ports`, which would cycle back through
|
package/dist/src/index.js
CHANGED
|
@@ -188,7 +188,7 @@ export function currentBranch(worktree) {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
/** Resolve the ports addon entry's transport for `worktree` via the SAME shared
|
|
191
|
-
* loader the
|
|
191
|
+
* loader the conductor tools use (`config.ts`'s `loadPortsTransport`) — one code
|
|
192
192
|
* path for both, so a missing package, invalid settings, or unsupported
|
|
193
193
|
* contract always yields the same bounded, redacted diagnostic no matter
|
|
194
194
|
* which entry point asked. Never falls back to another transport: a
|
package/dist/src/lock.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// BB-676 Task 3 — the one exclusive machine lock a tunnel reconciliation
|
|
2
2
|
// runs under, covering read → desired-state update → DNS/ingress reconcile →
|
|
3
|
-
// persisted result, across CLI processes AND
|
|
3
|
+
// persisted result, across CLI processes AND conductor tool calls.
|
|
4
4
|
//
|
|
5
5
|
// A JS `Promise`-based mutex only serializes within one process; two
|
|
6
6
|
// `bakers ports up` invocations from two worktrees are two OS processes, so the
|
package/dist/src/preset.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// (BB-201). In a conductor's `addons[]` the same package contributes its
|
|
6
6
|
// `inbox` (contract 2, see below): the `tunnel` message's Markdown result is
|
|
7
7
|
// rendered in the ticket's addon card in the web UI and in `bakers ui`, and the
|
|
8
|
-
//
|
|
8
|
+
// conductor answers it with the `ports_up` tool on its machine.
|
|
9
9
|
import { PORTS_TOOL_DEFINITIONS } from './tool-definitions.js';
|
|
10
10
|
export const commands = (acc) => [
|
|
11
11
|
...acc,
|
|
@@ -23,7 +23,8 @@ export const inbox = {
|
|
|
23
23
|
messages: {
|
|
24
24
|
tunnel: { label: 'Share tunnels', access: 'view' },
|
|
25
25
|
},
|
|
26
|
-
|
|
26
|
+
// Shares every eligible service through the same tool agents use.
|
|
27
|
+
bindings: { tunnel: { tool: 'ports_up', args: {} } },
|
|
27
28
|
};
|
|
28
29
|
// Configurable on either level; the machine entry's with wins.
|
|
29
30
|
export const scopes = ['machine', 'project'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-ports",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.858",
|
|
4
4
|
"description": "bakers.build ports command plugin: discover a ticket worktree's running services (DDEV, Designbook, ad-hoc listeners) and bring shareable tunnels up and down. The command half of BB-475; usable without the cockpit half.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"directory": "bakers-cli/addons/ports"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@bakers-build/addon-ddev": "^0.5.1-next.
|
|
26
|
+
"@bakers-build/addon-ddev": "^0.5.1-next.858",
|
|
27
27
|
"commander": "^12.1.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@bakers-build/conductor": "^0.5.1-next.
|
|
31
|
-
"@bakers-build/core": "^0.5.1-next.
|
|
30
|
+
"@bakers-build/conductor": "^0.5.1-next.858",
|
|
31
|
+
"@bakers-build/core": "^0.5.1-next.858"
|
|
32
32
|
},
|
|
33
33
|
"bakersBuild": {
|
|
34
|
-
"commit": "
|
|
34
|
+
"commit": "b031fba904f60f6ef154c28e69696bad51cadebc",
|
|
35
35
|
"channel": "next"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/dist/src/inbox.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { InboxMessageHandler } from '@bakers-build/conductor/contract';
|
|
2
|
-
import type { ClaimedDiscovery, ClaimedService } from './claims.js';
|
|
3
|
-
import { type OperationContext, type PortsTransport, type TunnelDesiredRecord } from './core.js';
|
|
4
|
-
/** The I/O the handler needs, injected so a test drives it with fixtures.
|
|
5
|
-
* `loadTransport` is the SAME shared loader the CLI uses (`config.ts`'s
|
|
6
|
-
* `loadPortsTransport`) — one code path for both, so settings validation
|
|
7
|
-
* cannot be bypassed by going through the inbox instead of the CLI. A
|
|
8
|
-
* missing/invalid/unresolvable transport resolves to `null`: the message
|
|
9
|
-
* answers a stable "no ports configuration" line rather than throwing a
|
|
10
|
-
* raw stack trace into the ticket's addon card. */
|
|
11
|
-
export interface TunnelHandlerDeps {
|
|
12
|
-
discover(worktree: string, ticket: string, zone: string): Promise<ClaimedDiscovery>;
|
|
13
|
-
readRecords(worktree: string): Promise<readonly TunnelDesiredRecord[]>;
|
|
14
|
-
bringUp(service: ClaimedService, ctx: OperationContext): Promise<{
|
|
15
|
-
ok: boolean;
|
|
16
|
-
message: string;
|
|
17
|
-
}>;
|
|
18
|
-
/** Same shared loader the CLI uses, surfaced with its own redacted
|
|
19
|
-
* diagnostic on failure — BB-681 review I5: a missing config and an
|
|
20
|
-
* unresolvable/invalid transport package are different problems and must
|
|
21
|
-
* not collapse onto one generic "no configuration" line here while the
|
|
22
|
-
* CLI reports the real one. */
|
|
23
|
-
loadTransport(): Promise<{
|
|
24
|
-
readonly ok: true;
|
|
25
|
-
readonly transport: PortsTransport;
|
|
26
|
-
} | {
|
|
27
|
-
readonly ok: false;
|
|
28
|
-
readonly message: string;
|
|
29
|
-
}>;
|
|
30
|
-
home(): string;
|
|
31
|
-
}
|
|
32
|
-
export declare function tunnelHandlers(deps: TunnelHandlerDeps): Record<string, InboxMessageHandler>;
|
|
33
|
-
/** The live handlers for the conductor's effective ports entry `with`
|
|
34
|
-
* (`options`, machine entry wins) — the conductor passes it per dispatch. */
|
|
35
|
-
export declare function handlersFor(options: unknown): Record<string, InboxMessageHandler>;
|
package/dist/src/inbox.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// BB-676 Task 4 — the ports addon's contract-2 handler (BB-661): a single
|
|
2
|
-
// `tunnel` message claims every eligible service of the worktree and shares
|
|
3
|
-
// each one not yet applied, then answers with one Markdown list.
|
|
4
|
-
//
|
|
5
|
-
// Only a claim with `rules.length > 0` is ever shared — an unknown, dead,
|
|
6
|
-
// stopped or not-exposed service never reaches `bringUp` (spec "Addon
|
|
7
|
-
// claims": "No unclaimed tunnels"). Liveness is read from the machine's
|
|
8
|
-
// APPLIED state, never a per-route PID — a route is up because its record
|
|
9
|
-
// says so, not because some process on this host answers to a signal.
|
|
10
|
-
import { realpathSync } from 'node:fs';
|
|
11
|
-
import { homeBbDir } from '@bakers-build/core';
|
|
12
|
-
import { servicesToShare, shareAll } from './claim-share.js';
|
|
13
|
-
import { discoverClaimedServices } from './claims.js';
|
|
14
|
-
import { assertNoMachinePorts, bringUpTunnel, loadPortsTransport, readMachineTunnelRecords, withProblems, } from './core.js';
|
|
15
|
-
import { nodeDeps, nodeHttpProbe, nodeTunnelOpsDeps } from './deps-node.js';
|
|
16
|
-
import { serviceRules } from './service-config.js';
|
|
17
|
-
import { tunnelMarkdown } from './tunnel-result.js';
|
|
18
|
-
/** The worktree as the CLI sees it (`process.cwd()` is already real): DDEV
|
|
19
|
-
* labels containers with the real path and discovery matches it exactly, so a
|
|
20
|
-
* symlinked path from the server would find nothing (BB-693). */
|
|
21
|
-
function canonicalPath(path) {
|
|
22
|
-
try {
|
|
23
|
-
return realpathSync(path);
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return path;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export function tunnelHandlers(deps) {
|
|
30
|
-
return {
|
|
31
|
-
tunnel: async (request) => {
|
|
32
|
-
const loaded = await deps.loadTransport();
|
|
33
|
-
if (!loaded.ok) {
|
|
34
|
-
return { markdown: loaded.message };
|
|
35
|
-
}
|
|
36
|
-
const transport = loaded.transport;
|
|
37
|
-
const ticket = request.ticket.identifier;
|
|
38
|
-
const worktree = canonicalPath(request.worktreePath);
|
|
39
|
-
const discovery = await deps.discover(worktree, ticket, transport.zone ?? '');
|
|
40
|
-
const ctx = {
|
|
41
|
-
worktree,
|
|
42
|
-
ticket,
|
|
43
|
-
home: deps.home(),
|
|
44
|
-
transport,
|
|
45
|
-
signal: request.signal,
|
|
46
|
-
};
|
|
47
|
-
const outcomes = await shareAll(servicesToShare(discovery), (s) => deps.bringUp(s, ctx));
|
|
48
|
-
const failures = outcomes
|
|
49
|
-
.filter(({ result }) => !result.ok)
|
|
50
|
-
.map(({ service, result }) => ({ service, message: result.message }));
|
|
51
|
-
const after = await deps.readRecords(worktree);
|
|
52
|
-
return { markdown: tunnelMarkdown(discovery, after, failures) };
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
/** The live handlers for the conductor's effective ports entry `with`
|
|
57
|
-
* (`options`, machine entry wins) — the conductor passes it per dispatch. */
|
|
58
|
-
export function handlersFor(options) {
|
|
59
|
-
return tunnelHandlers({
|
|
60
|
-
discover: (worktree, ticket, zone) => discoverClaimedServices(worktree, nodeDeps, {
|
|
61
|
-
ticket,
|
|
62
|
-
zone,
|
|
63
|
-
probe: nodeHttpProbe,
|
|
64
|
-
rules: serviceRules(options),
|
|
65
|
-
}),
|
|
66
|
-
readRecords: (worktree) => readMachineTunnelRecords(worktree, homeBbDir(), nodeTunnelOpsDeps),
|
|
67
|
-
bringUp: (service, ctx) => bringUpTunnel(service.rules[0], ctx, nodeTunnelOpsDeps),
|
|
68
|
-
loadTransport: async () => {
|
|
69
|
-
// The conductor hands the merged `with`; a bad setting answers here
|
|
70
|
-
// instead of a silently empty claim list.
|
|
71
|
-
const [problem] = withProblems(options);
|
|
72
|
-
if (problem)
|
|
73
|
-
return { ok: false, message: problem };
|
|
74
|
-
try {
|
|
75
|
-
await assertNoMachinePorts();
|
|
76
|
-
const transport = await loadPortsTransport(options, homeBbDir());
|
|
77
|
-
return { ok: true, transport };
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
// The loader already produces a bounded, redacted diagnostic (missing
|
|
81
|
-
// entry, unresolvable package, rejected settings) — the SAME message
|
|
82
|
-
// the CLI prints, never a raw stack trace into the ticket's addon card.
|
|
83
|
-
return {
|
|
84
|
-
ok: false,
|
|
85
|
-
message: err instanceof Error ? err.message : String(err),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
home: () => homeBbDir(),
|
|
90
|
-
});
|
|
91
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ClaimedDiscovery, ClaimedService } from './claims.js';
|
|
2
|
-
import type { TunnelDesiredRecord } from './core.js';
|
|
3
|
-
export declare function tunnelMarkdown(discovery: ClaimedDiscovery, records: readonly TunnelDesiredRecord[], failures?: readonly {
|
|
4
|
-
service: ClaimedService;
|
|
5
|
-
message: string;
|
|
6
|
-
}[]): string;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// BB-676 Task 4 — the `tunnel` message's Markdown answer (BB-661 contract
|
|
2
|
-
// 2): one bullet per CLAIMED service, driven by the machine's applied/pending/
|
|
3
|
-
// error record for its key rather than a per-route PID. Two site keys sharing
|
|
4
|
-
// a base name (e.g. `drupal-admin`, `drupal-members`) each render their own
|
|
5
|
-
// line (plan review focus 3): matching is by `key`, never by a shared port.
|
|
6
|
-
function serviceLine(service, record) {
|
|
7
|
-
const limitation = service.limitation ? ` — ${service.limitation}` : '';
|
|
8
|
-
if (service.status === 'stopped') {
|
|
9
|
-
return `- ${service.key} (${service.claim}) — not running`;
|
|
10
|
-
}
|
|
11
|
-
if (service.rules.length === 0) {
|
|
12
|
-
return `- ${service.key} (${service.claim}) — no addon${limitation}`;
|
|
13
|
-
}
|
|
14
|
-
if (!record || record.desired !== 'present') {
|
|
15
|
-
return `- ${service.key} (${service.claim}) — local only: ${service.local}${limitation}`;
|
|
16
|
-
}
|
|
17
|
-
if (record.applied === 'applied') {
|
|
18
|
-
// The ACTUAL confirmed `record.url` wins when the transport reports one
|
|
19
|
-
// (e.g. Quick's allocated hostname, which is never predictable ahead of
|
|
20
|
-
// time); only a zone-based transport's stable `hostname` falls back to
|
|
21
|
-
// the derived `https://` URL.
|
|
22
|
-
const url = record.url ?? `https://${record.hostname}`;
|
|
23
|
-
return `- ${service.key} (${service.claim}) — [${url}](${url}) (local: ${service.local})${limitation}`;
|
|
24
|
-
}
|
|
25
|
-
if (record.applied === 'error') {
|
|
26
|
-
return `- ${service.key} (${service.claim}) — failed to share: ${record.error ?? 'unknown error'}`;
|
|
27
|
-
}
|
|
28
|
-
return `- ${service.key} (${service.claim}) — pending`;
|
|
29
|
-
}
|
|
30
|
-
export function tunnelMarkdown(discovery, records, failures = []) {
|
|
31
|
-
const byKey = new Map(records.map((r) => [r.key, r]));
|
|
32
|
-
const lines = discovery.services.map((s) => serviceLine(s, byKey.get(s.key)));
|
|
33
|
-
for (const failure of failures) {
|
|
34
|
-
if (byKey.get(failure.service.key)?.applied === 'error')
|
|
35
|
-
continue;
|
|
36
|
-
lines.push(`- ${failure.service.key} (${failure.service.claim}) — failed to share: ${failure.message}`);
|
|
37
|
-
}
|
|
38
|
-
return lines.length > 0
|
|
39
|
-
? lines.join('\n')
|
|
40
|
-
: 'No services found in this worktree.';
|
|
41
|
-
}
|