@hop-top/kit 0.5.0-alpha.2 → 0.5.0-alpha.3

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 CHANGED
@@ -4,6 +4,26 @@ All notable changes to `@hop-top/kit` are documented in this file.
4
4
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
5
5
  versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.5.0-alpha.3](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.2...kit-ts/v0.5.0-alpha.3) (2026-09-05)
8
+
9
+ The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.3. This release includes new features and bug fixes.
10
+
11
+
12
+ ### Features
13
+
14
+ * **sdk:** EXIT_GENERIC and generic error constructor in all SDKs
15
+ * **ts:** EXIT_GENERIC and genericError for the exit-1 class
16
+ * **ts:** serve --enable/--disable and timeout flags
17
+ * **ts:** serve cross-language contract and TypeScript implementation
18
+ * **ts:** serve hierarchy and service lifecycle
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * **parity:** record and implement serve --enable/--disable and timeout flags
24
+
25
+ Full diff: [kit-ts/v0.5.0-alpha.2...kit-ts/v0.5.0-alpha.3](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.2...kit-ts/v0.5.0-alpha.3)
26
+
7
27
  ## [0.5.0-alpha.2](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.1...kit-ts/v0.5.0-alpha.2) (2026-09-04)
8
28
 
9
29
  The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.2. This release includes new features and bug fixes.
package/README.md CHANGED
@@ -274,9 +274,105 @@ render(process.stdout, JSON_FORMAT, { ok: true });
274
274
  action resolution, completions, registries, and OS handler metadata.
275
275
  - `@hop-top/kit/tui` — TUI toolkit (parity, anim, prompts).
276
276
  - `@hop-top/kit/mcp` — dual-spec MCP surface (see [MCP surface](#mcp-surface)).
277
+ - `@hop-top/kit/serve` — the serve hierarchy and service lifecycle (see
278
+ [Serve](#serve)).
277
279
 
278
280
  See package.json `exports` for the full list.
279
281
 
282
+ ## Serve
283
+
284
+ `<tool> serve` supervises every configured and enabled service;
285
+ `<tool> serve <service>` selects exactly one. Both forms share one
286
+ lifecycle, so a service started by the selector observes the same
287
+ readiness, shutdown, and exit semantics as the same service started by
288
+ the supervisor.
289
+
290
+ The normative contract is
291
+ [`docs/contracts/serve-lifecycle.md`](../../docs/contracts/serve-lifecycle.md);
292
+ this module implements the part of it §"Cross-language parity" makes
293
+ binding on every SDK. Go is the reference implementation.
294
+
295
+ ```ts
296
+ import { createCLI } from '@hop-top/kit/cli';
297
+ import { ServiceRegistry, registerServe } from '@hop-top/kit/serve';
298
+
299
+ const registry = new ServiceRegistry();
300
+ registry.register({
301
+ name: 'api',
302
+ async start(signal, ready) {
303
+ // Report ready once every acquisition that can fail has succeeded.
304
+ ready();
305
+ await new Promise<void>((r) =>
306
+ signal.addEventListener('abort', () => r(), { once: true }));
307
+ },
308
+ ready: () => true,
309
+ async stop() { /* drain, then release */ },
310
+ });
311
+
312
+ const { program } = createCLI({
313
+ name: 'mytool', version: '1.0.0', description: 'My tool',
314
+ });
315
+ registerServe(program, { registry, configs: { api: { enabled: true } } });
316
+ program.parse();
317
+ ```
318
+
319
+ ### The override rule
320
+
321
+ `serve <service>` starts the named service **even when
322
+ `services.<name>.enabled` is false**, provided it is registered and its
323
+ configuration and policy validate. Enablement answers "does the
324
+ supervisor start this by default"; it is not an authorization decision,
325
+ and an operator naming a service has already made the decision the flag
326
+ exists to automate.
327
+
328
+ Under the supervisor form a disabled service is skipped silently and
329
+ does not affect the exit code. A supervisor invocation that resolves to
330
+ zero services exits 2 rather than 0: a process that exits 0 without
331
+ listening is indistinguishable from a successful start to systemd or a
332
+ container runtime.
333
+
334
+ ### Configuration
335
+
336
+ | Key | Type | Default |
337
+ |-----|------|---------|
338
+ | `services.<name>.enabled` | bool | `false` |
339
+ | `services.<name>.ready_timeout` | duration | `30s` |
340
+ | `services.<name>.stop_timeout` | duration | `30s` |
341
+ | `services.failure_policy` | `fail-fast` \| `isolate` | `fail-fast` |
342
+ | `services.shutdown_timeout` | duration | `60s` |
343
+
344
+ `registerServe` takes the resolved blocks as `configs`; this port does
345
+ not resolve dotted keys itself, because `@hop-top/kit/config` merges
346
+ whole documents rather than resolving per key. The contract requires the
347
+ key *names*, not a particular resolution engine.
348
+
349
+ ### Exit codes
350
+
351
+ | Situation | Code | Exit |
352
+ |-----------|------|------|
353
+ | Clean stop after a signal | `OK` | 0 |
354
+ | Invalid selection, invalid config, zero services | `USAGE` | 2 |
355
+ | Unknown service name | `NOT_FOUND` | 3 |
356
+ | Policy denied | `UNAUTHORIZED` | 5 |
357
+ | Start failure, runtime crash, shutdown budget exceeded | `GENERIC` | 1 |
358
+
359
+ ### Lifecycle events
360
+
361
+ Six transitions are surfaced, on the bus when a `publisher` is wired and
362
+ through the `logger` either way:
363
+ `kit.serve.service.{started,ready_reported,failed,stopped}` and
364
+ `kit.serve.supervisor.{ready_reported,stopped}`. The service identifier
365
+ travels in the payload, never in the topic, so a subscriber is not
366
+ forced to re-bind when a tool gains a service.
367
+
368
+ ### What this port does not do
369
+
370
+ The contract rules these out as Go-only; they are absent here by design,
371
+ not unimplemented: the REST/OpenAPI projection of the command tree, the
372
+ Unix socket service, `cmdreflect`-driven discovery, and the permission,
373
+ provenance, and audit surface. This SDK ships no HTTP or socket server,
374
+ so a service that listens is the adopter's to write.
375
+
280
376
  ## MCP surface
281
377
 
282
378
  Serves the Model Context Protocol over a bridged command tree, one MCP
@@ -1,7 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  import { E as ErrOffline, O as OfflineError, g as guardFetch, a as isOffline, b as isOfflineError, w as withOffline } from './netpolicy-asvCfwi8.js';
3
3
  import { Writable } from 'node:stream';
4
- import { F as Format } from './output-VFFLqor9.js';
4
+ import { F as Format } from './output-4aXs91GY.js';
5
5
 
6
6
  /**
7
7
  * @module tui/parity
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import 'commander';
2
- export { C as CLIConfig, a as CLIResult, D as Dark, H as Hint, b as HintOptions, c as HintSet, N as Neon, P as Palette, T as Theme, d as active, e as applyHelpTheme, f as buildTheme, g as channel, i as createCLI, j as getCommandGroup, k as getStreamDefs, l as hintsEnabled, r as registerStream, m as registerUpgradeHints, n as registerVersionHints, o as renderHints, s as setCommandGroup, p as streamFlagName, q as streamLabel, t as streamOutput, v as verboseCount, u as verbosityFlagSpec, w as verbosityShorthand } from './cli-DgOEOsPB.js';
2
+ export { C as CLIConfig, a as CLIResult, D as Dark, H as Hint, b as HintOptions, c as HintSet, N as Neon, P as Palette, T as Theme, d as active, e as applyHelpTheme, f as buildTheme, g as channel, i as createCLI, j as getCommandGroup, k as getStreamDefs, l as hintsEnabled, r as registerStream, m as registerUpgradeHints, n as registerVersionHints, o as renderHints, s as setCommandGroup, p as streamFlagName, q as streamLabel, t as streamOutput, v as verboseCount, u as verbosityFlagSpec, w as verbosityShorthand } from './cli-DLygZLi9.js';
3
3
  export { E as ErrOffline, O as OfflineError, g as guardFetch, a as isOffline, b as isOfflineError, w as withOffline } from './netpolicy-asvCfwi8.js';
4
4
  import 'node:stream';
5
- import './output-VFFLqor9.js';
5
+ import './output-4aXs91GY.js';
6
+ import './error-DISJKeDu.js';
package/dist/cli.js CHANGED
@@ -118,7 +118,8 @@ var parity_default = {
118
118
  output: "stderr"
119
119
  },
120
120
  extends: [
121
- "scope-defaults.json"
121
+ "scope-defaults.json",
122
+ "serve.json"
122
123
  ]
123
124
  };
124
125
 
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @module output/error
3
+ *
4
+ * Structured-error envelope. Mirrors Go's `go/console/output` error
5
+ * envelope: when a command fails under `--format json|yaml`, the error is
6
+ * materialized as a {@link CliError} and rendered to stderr by
7
+ * {@link renderError}. Plaintext mode (`--format table` or unset) prints
8
+ * `"Code: Message\nFix: ...\n"`.
9
+ *
10
+ * Fields use the on-wire snake_case keys directly (like the telemetry
11
+ * `Envelope`) so `JSON.stringify` is wire-exact; empty optional fields
12
+ * stay off the wire, mirroring Go's `omitempty`.
13
+ */
14
+ /** Marks a failure a retry may clear (rate limit, timeout, upstream blip). */
15
+ declare const TRANSIENCE_TRANSIENT = "transient";
16
+ /**
17
+ * Marks a failure retrying cannot clear without changing the input or the
18
+ * environment.
19
+ */
20
+ declare const TRANSIENCE_PERMANENT = "permanent";
21
+ /**
22
+ * Marks a failure kit cannot classify. Agents should treat retries as
23
+ * best-effort and bounded.
24
+ */
25
+ declare const TRANSIENCE_UNKNOWN = "unknown";
26
+ declare const CODE_OK = "OK";
27
+ declare const CODE_GENERIC = "GENERIC";
28
+ declare const CODE_USAGE = "USAGE";
29
+ declare const CODE_NOT_FOUND = "NOT_FOUND";
30
+ declare const CODE_CONFLICT = "CONFLICT";
31
+ declare const CODE_UNAUTHORIZED = "UNAUTHORIZED";
32
+ declare const CODE_TRANSIENT = "TRANSIENT";
33
+ declare const CODE_PROVENANCE_MISSING = "PROVENANCE_MISSING";
34
+ declare const CODE_RATE_LIMITED = "RATE_LIMITED";
35
+ /**
36
+ * Spec-assigned exit code for the generic failure class: the command
37
+ * failed and no narrower code applies. Pair it with {@link genericError}
38
+ * rather than hand-rolling exit 1, so the envelope carries a transience
39
+ * class.
40
+ */
41
+ declare const EXIT_GENERIC = 1;
42
+ /**
43
+ * Spec-assigned exit code for transient/retryable failures (Factor 11).
44
+ * Agents branch on it before parsing stderr: exit 6 means a retry may
45
+ * clear the failure.
46
+ */
47
+ declare const EXIT_TRANSIENT = 6;
48
+ /** Conventional exit code for Factor-10 rate-limit refusals. */
49
+ declare const EXIT_RATE_LIMITED = 64;
50
+ /**
51
+ * Conventional exit code for Factor-12 strict-mode provenance refusals.
52
+ * Lives at 65 in kit's extension band (alongside RATE_LIMITED at 64):
53
+ * the spec reserves 0-6 for its core taxonomy and leaves >6 to per-tool
54
+ * codes, and kit as a library stays out of the low per-tool range.
55
+ */
56
+ declare const EXIT_PROVENANCE_MISSING = 65;
57
+ /**
58
+ * Structured-error envelope rendered to stderr when `--format json|yaml`
59
+ * is set. Keys are the on-wire snake_case names.
60
+ *
61
+ * `transience` classifies the failure for retry decisions (Factor 4):
62
+ * transient (retry-worthy), permanent (do not retry), or unknown.
63
+ * Constructors and {@link wrapError} populate it; {@link renderError}
64
+ * normalizes an unset value to unknown so every structured error carries
65
+ * a valid class on the wire.
66
+ */
67
+ interface CliError {
68
+ code: string;
69
+ message: string;
70
+ cause?: string;
71
+ suggested_fix?: string;
72
+ alternatives?: string[];
73
+ exit_code: number;
74
+ transience?: string;
75
+ }
76
+ /**
77
+ * Default transience class for one of the standard codes. Unrecognized
78
+ * (adopter-defined) codes map to unknown; adopters set `transience`
79
+ * (or use {@link withTransience}) to classify their own codes.
80
+ */
81
+ declare function transienceForCode(code: string): string;
82
+ /**
83
+ * Builds an envelope from `err`, retaining it for {@link unwrapError}
84
+ * while rendering as `code` and message. Transience defaults from the
85
+ * code via {@link transienceForCode}; use {@link withTransience} to
86
+ * override.
87
+ */
88
+ declare function wrapError(err: unknown, code: string, exitCode: number): CliError | null;
89
+ /**
90
+ * The error this envelope was built from via {@link wrapError}, so
91
+ * callers can classify failures by cause instead of string-matching
92
+ * `message`. Mirrors Go's `(*Error).Unwrap`.
93
+ */
94
+ declare function unwrapError(e: CliError): unknown;
95
+ /**
96
+ * Copy of `e` with `transience` set, every other field (and the retained
97
+ * source error) untouched. Copies rather than mutating: adopters
98
+ * commonly share module-level envelopes, and writing to one would leak
99
+ * across call sites.
100
+ */
101
+ declare function withTransience(e: CliError, transience: string): CliError;
102
+ /**
103
+ * CODE_GENERIC envelope with exit code 1. The catch-all for failures no
104
+ * narrower code describes; permanent because retrying the same input
105
+ * in the same environment is not expected to help. Wrapping an
106
+ * arbitrary error as CODE_GENERIC via {@link wrapError} still defaults
107
+ * to unknown.
108
+ */
109
+ declare function genericError(message: string): CliError;
110
+ /** CODE_NOT_FOUND envelope with exit code 3. */
111
+ declare function notFoundError(message: string): CliError;
112
+ /** CODE_CONFLICT envelope with exit code 4. */
113
+ declare function conflictError(message: string): CliError;
114
+ /** CODE_UNAUTHORIZED envelope with exit code 5. */
115
+ declare function unauthorizedError(message: string): CliError;
116
+ /** CODE_USAGE envelope with exit code 2. */
117
+ declare function usageError(message: string): CliError;
118
+ /**
119
+ * CODE_TRANSIENT envelope with exit code 6 (Factor 11). Use it for
120
+ * failures a retry may clear: upstream timeouts, connection resets,
121
+ * service-unavailable responses.
122
+ */
123
+ declare function transientError(message: string): CliError;
124
+ /** CODE_RATE_LIMITED envelope with exit code 64 (Factor 10). */
125
+ declare function rateLimitedError(message: string): CliError;
126
+ /**
127
+ * CODE_PROVENANCE_MISSING envelope with exit code 65 (Factor 12).
128
+ * `detail` is a free-form string suitable for the `cause` slot
129
+ * (typically the JSON-pointer list of offending fields).
130
+ */
131
+ declare function provenanceMissingError(detail: string): CliError;
132
+ /**
133
+ * Writes `err` to `w` in the requested format. `format === ''` or
134
+ * `'table'` renders human-readable plain text (`"Code: Message\nFix:
135
+ * ..."`); JSON/YAML render the envelope structurally. An unset
136
+ * transience is normalized to unknown on the wire (Factor 4) without
137
+ * mutating `err`. Always returns; the caller decides the exit code from
138
+ * `err.exit_code` after rendering.
139
+ */
140
+ declare function renderError(w: {
141
+ write(chunk: string): unknown;
142
+ }, format: string, err: CliError | null | undefined): void;
143
+
144
+ export { wrapError as A, CODE_CONFLICT as C, EXIT_GENERIC as E, TRANSIENCE_PERMANENT as T, CODE_GENERIC as a, CODE_NOT_FOUND as b, CODE_OK as c, CODE_PROVENANCE_MISSING as d, CODE_RATE_LIMITED as e, CODE_TRANSIENT as f, CODE_UNAUTHORIZED as g, CODE_USAGE as h, type CliError as i, EXIT_PROVENANCE_MISSING as j, EXIT_RATE_LIMITED as k, EXIT_TRANSIENT as l, TRANSIENCE_TRANSIENT as m, TRANSIENCE_UNKNOWN as n, conflictError as o, genericError as p, notFoundError as q, provenanceMissingError as r, rateLimitedError as s, renderError as t, transienceForCode as u, transientError as v, unauthorizedError as w, unwrapError as x, usageError as y, withTransience as z };
@@ -1,4 +1,4 @@
1
- import { T as Theme } from './cli-DgOEOsPB.js';
1
+ import { T as Theme } from './cli-DLygZLi9.js';
2
2
 
3
3
  /**
4
4
  * @module tui/badge
package/dist/index.d.ts CHANGED
@@ -2,25 +2,27 @@ export { g as aim } from './aim-CTp-kJW2.js';
2
2
  export { c as alias } from './alias-dhhr08Ei.js';
3
3
  export { e as api } from './api-miiso81x.js';
4
4
  export { a as auth } from './auth-2-jfgiHn.js';
5
- export { h as cli } from './cli-DgOEOsPB.js';
5
+ export { h as cli } from './cli-DLygZLi9.js';
6
6
  export { c as config } from './config-BUY7_W2n.js';
7
7
  export { e as errcorrect } from './errcorrect-BcX1Ft0K.js';
8
8
  export { i as id } from './index-QSffbLnj.js';
9
9
  export { s as llm } from './llm-B5XUWH8T.js';
10
10
  export { ao as mcp } from './index-MLrRDvEG.js';
11
11
  export { n as netpolicy } from './netpolicy-asvCfwi8.js';
12
- export { I as output } from './output-VFFLqor9.js';
12
+ export { l as output } from './output-4aXs91GY.js';
13
13
  export { p as progress } from './progress-CAzyxeWl.js';
14
14
  export { p as provenance } from './provenance-SMFHm5gx.js';
15
15
  export { r as routellm } from './routellm-PGSt2D1y.js';
16
16
  export { r as rpc } from './rpc-D5xLEf8V.js';
17
17
  export { s as safety } from './safety-CUaYEjZc.js';
18
18
  export { s as scope } from './scope-BrhYB4ij.js';
19
+ export { M as serve } from './serve-DE-jscpb.js';
19
20
  export { s as stream } from './stream-CrjeCp0M.js';
20
21
  export { i as telemetry } from './index-C3Zw4wDJ.js';
21
- export { i as tui } from './index--C7Mtsmm.js';
22
+ export { i as tui } from './index-Bc5c7Ty5.js';
22
23
  export { u as upgrade } from './upgrade-p_zh3pvV.js';
23
24
  export { x as xdg } from './xdg-DB7Shoib.js';
24
25
  import 'commander';
25
26
  import 'node:stream';
26
27
  import 'zod';
28
+ import './error-DISJKeDu.js';