@sentropic/h2a-cli 0.1.1 → 0.1.6

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.
Files changed (67) hide show
  1. package/dist/bin.js +30 -2
  2. package/dist/bin.js.map +1 -1
  3. package/dist/cli-contract.d.ts +62 -0
  4. package/dist/cli-contract.d.ts.map +1 -0
  5. package/dist/cli-contract.js +239 -0
  6. package/dist/cli-contract.js.map +1 -0
  7. package/dist/cli.d.ts +51 -0
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +711 -2
  10. package/dist/cli.js.map +1 -1
  11. package/dist/hosts/claude.d.ts +11 -6
  12. package/dist/hosts/claude.d.ts.map +1 -1
  13. package/dist/hosts/claude.js +40 -1
  14. package/dist/hosts/claude.js.map +1 -1
  15. package/dist/hosts/codex.d.ts +64 -6
  16. package/dist/hosts/codex.d.ts.map +1 -1
  17. package/dist/hosts/codex.js +39 -1
  18. package/dist/hosts/codex.js.map +1 -1
  19. package/dist/hosts/gemini.d.ts +8 -6
  20. package/dist/hosts/gemini.d.ts.map +1 -1
  21. package/dist/hosts/gemini.js +9 -1
  22. package/dist/hosts/gemini.js.map +1 -1
  23. package/dist/index.d.ts +8 -34
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +5 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/runtime/local-files/index.d.ts +5 -0
  28. package/dist/runtime/local-files/index.d.ts.map +1 -0
  29. package/dist/runtime/local-files/index.js +5 -0
  30. package/dist/runtime/local-files/index.js.map +1 -0
  31. package/dist/runtime/local-files/locks.d.ts +43 -0
  32. package/dist/runtime/local-files/locks.d.ts.map +1 -0
  33. package/dist/runtime/local-files/locks.js +197 -0
  34. package/dist/runtime/local-files/locks.js.map +1 -0
  35. package/dist/runtime/local-files/paths.d.ts +18 -0
  36. package/dist/runtime/local-files/paths.d.ts.map +1 -0
  37. package/dist/runtime/local-files/paths.js +28 -0
  38. package/dist/runtime/local-files/paths.js.map +1 -0
  39. package/dist/runtime/local-files/schema.d.ts +47 -0
  40. package/dist/runtime/local-files/schema.d.ts.map +1 -0
  41. package/dist/runtime/local-files/schema.js +77 -0
  42. package/dist/runtime/local-files/schema.js.map +1 -0
  43. package/dist/runtime/local-files/store.d.ts +44 -0
  44. package/dist/runtime/local-files/store.d.ts.map +1 -0
  45. package/dist/runtime/local-files/store.js +407 -0
  46. package/dist/runtime/local-files/store.js.map +1 -0
  47. package/dist/runtime/mcp/handlers.d.ts +62 -0
  48. package/dist/runtime/mcp/handlers.d.ts.map +1 -0
  49. package/dist/runtime/mcp/handlers.js +261 -0
  50. package/dist/runtime/mcp/handlers.js.map +1 -0
  51. package/dist/runtime/mcp/index.d.ts +5 -0
  52. package/dist/runtime/mcp/index.d.ts.map +1 -0
  53. package/dist/runtime/mcp/index.js +5 -0
  54. package/dist/runtime/mcp/index.js.map +1 -0
  55. package/dist/runtime/mcp/server.d.ts +26 -0
  56. package/dist/runtime/mcp/server.d.ts.map +1 -0
  57. package/dist/runtime/mcp/server.js +45 -0
  58. package/dist/runtime/mcp/server.js.map +1 -0
  59. package/dist/runtime/mcp/stdio.d.ts +21 -0
  60. package/dist/runtime/mcp/stdio.d.ts.map +1 -0
  61. package/dist/runtime/mcp/stdio.js +103 -0
  62. package/dist/runtime/mcp/stdio.js.map +1 -0
  63. package/dist/runtime/mcp/tools.d.ts +19 -0
  64. package/dist/runtime/mcp/tools.d.ts.map +1 -0
  65. package/dist/runtime/mcp/tools.js +175 -0
  66. package/dist/runtime/mcp/tools.js.map +1 -0
  67. package/package.json +3 -3
package/dist/bin.js CHANGED
@@ -1,4 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import { runCli } from "./cli.js";
3
- process.exitCode = runCli();
2
+ import { runCli, runMcpServe } from "./cli.js";
3
+ const argv = process.argv.slice(2);
4
+ // `mcp-serve` is an async long-running JSON-RPC loop on real stdin; the
5
+ // synchronous `runCli` cannot represent it. We dispatch directly here.
6
+ if (argv[0] === "mcp-serve") {
7
+ const flags = {};
8
+ for (let i = 1; i < argv.length; i++) {
9
+ const token = argv[i];
10
+ if (token.startsWith("--")) {
11
+ const key = token.slice(2);
12
+ const next = argv[i + 1];
13
+ if (next !== undefined && !next.startsWith("--")) {
14
+ flags[key] = next;
15
+ i++;
16
+ }
17
+ else {
18
+ flags[key] = "true";
19
+ }
20
+ }
21
+ }
22
+ runMcpServe(flags).then((rc) => {
23
+ process.exitCode = rc;
24
+ }, (err) => {
25
+ process.stderr.write(`h2a mcp-serve: fatal: ${err.message}\n`);
26
+ process.exitCode = 1;
27
+ });
28
+ }
29
+ else {
30
+ process.exitCode = runCli(argv);
31
+ }
4
32
  //# sourceMappingURL=bin.js.map
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,CAAC,QAAQ,GAAG,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,wEAAwE;AACxE,uEAAuE;AACvE,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC;IAC5B,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACzB,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjD,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;gBAClB,CAAC,EAAE,CAAC;YACN,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;IACD,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CACrB,CAAC,EAAE,EAAE,EAAE;QACL,OAAO,CAAC,QAAQ,GAAG,EAAE,CAAC;IACxB,CAAC,EACD,CAAC,GAAG,EAAE,EAAE;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yBAA0B,GAAa,CAAC,OAAO,IAAI,CAAC,CAAC;QAC1E,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;AACJ,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Stable JSON output contract + exit-code table for the `h2a` CLI surface.
3
+ *
4
+ * This module is the **machine-readable counterpart** of `docs/cli-contract.md`
5
+ * (DEC-034). Every verb exposed by `runCli` appears here with:
6
+ *
7
+ * - `outputShape`: one of three canonical envelopes (see below).
8
+ * - `exitCodes`: the subset of {0,1,2,3} the verb can return.
9
+ * - `requiredFlags` / `optionalFlags`: documented flag surface.
10
+ *
11
+ * Envelope shapes
12
+ * ---------------
13
+ *
14
+ * - `resource` — single entity persisted/loaded by the verb. Stdout is the
15
+ * bare JSON of that entity (no `{ok}` wrapper). Examples: a negotiation
16
+ * record, a journal entry, an envelope, the MCP config snippet for a host.
17
+ * - `list` — bare JSON array. Examples: `discover`, `inbox read`,
18
+ * `negotiate journal`.
19
+ * - `action` — confirmation envelope `{ ok: true, ...details }` for verbs
20
+ * that perform side effects but do not return a natural entity (`init`,
21
+ * `register`, `inbox put`, `outbox put`, `negotiate stabilize`,
22
+ * `host setup --write`).
23
+ * - `text` — non-JSON human output (currently only `--help`).
24
+ * - `stream` — long-running framed transport (`mcp-serve`, JSON-RPC 2.0
25
+ * over stdio); no single stdout payload.
26
+ *
27
+ * Exit-code table
28
+ * ---------------
29
+ *
30
+ * - `0` success.
31
+ * - `1` user error — bad flag, missing required flag, invalid JSON,
32
+ * validation failure on user input, unknown verb/subverb/host.
33
+ * - `2` runtime/state error — store conflict or business-rule failure
34
+ * (negotiation not found, already open, already stabilized, signature
35
+ * fails verification, quorum incomplete, broken journal, divergent
36
+ * pre-existing config file).
37
+ * - `3` I/O / OS error — file unreadable, permission denied, write
38
+ * refused by the filesystem.
39
+ *
40
+ * DEC-034 freezes this contract. Future breaking changes require a new DEC
41
+ * and a major version bump on `@sentropic/h2a-cli`.
42
+ */
43
+ export type H2ACliOutputShape = "resource" | "list" | "action" | "text" | "stream";
44
+ export type H2ACliExitCode = 0 | 1 | 2 | 3;
45
+ export interface H2ACliVerbContract {
46
+ /** Full verb path, space-separated (`"negotiate open"`, `"host setup"`). */
47
+ readonly verb: string;
48
+ /** Canonical envelope of the stdout payload on success. */
49
+ readonly outputShape: H2ACliOutputShape;
50
+ /** Exit codes this verb can produce. Always includes `0` for success. */
51
+ readonly exitCodes: readonly H2ACliExitCode[];
52
+ /** Flags required for a happy-path invocation. */
53
+ readonly requiredFlags: readonly string[];
54
+ /** Flags accepted but optional. */
55
+ readonly optionalFlags: readonly string[];
56
+ /** One-line human description. */
57
+ readonly description: string;
58
+ }
59
+ export declare const H2A_CLI_VERB_CONTRACTS: readonly H2ACliVerbContract[];
60
+ /** Map of verb-path → contract for O(1) lookups in tests and tooling. */
61
+ export declare const H2A_CLI_VERB_CONTRACT_BY_VERB: ReadonlyMap<string, H2ACliVerbContract>;
62
+ //# sourceMappingURL=cli-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-contract.d.ts","sourceRoot":"","sources":["../src/cli-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEnF,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C,kDAAkD;IAClD,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,mCAAmC;IACnC,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,kCAAkC;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,sBAAsB,EAAE,SAAS,kBAAkB,EA2MtD,CAAC;AAEX,yEAAyE;AACzE,eAAO,MAAM,6BAA6B,EAAE,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAEjF,CAAC"}
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Stable JSON output contract + exit-code table for the `h2a` CLI surface.
3
+ *
4
+ * This module is the **machine-readable counterpart** of `docs/cli-contract.md`
5
+ * (DEC-034). Every verb exposed by `runCli` appears here with:
6
+ *
7
+ * - `outputShape`: one of three canonical envelopes (see below).
8
+ * - `exitCodes`: the subset of {0,1,2,3} the verb can return.
9
+ * - `requiredFlags` / `optionalFlags`: documented flag surface.
10
+ *
11
+ * Envelope shapes
12
+ * ---------------
13
+ *
14
+ * - `resource` — single entity persisted/loaded by the verb. Stdout is the
15
+ * bare JSON of that entity (no `{ok}` wrapper). Examples: a negotiation
16
+ * record, a journal entry, an envelope, the MCP config snippet for a host.
17
+ * - `list` — bare JSON array. Examples: `discover`, `inbox read`,
18
+ * `negotiate journal`.
19
+ * - `action` — confirmation envelope `{ ok: true, ...details }` for verbs
20
+ * that perform side effects but do not return a natural entity (`init`,
21
+ * `register`, `inbox put`, `outbox put`, `negotiate stabilize`,
22
+ * `host setup --write`).
23
+ * - `text` — non-JSON human output (currently only `--help`).
24
+ * - `stream` — long-running framed transport (`mcp-serve`, JSON-RPC 2.0
25
+ * over stdio); no single stdout payload.
26
+ *
27
+ * Exit-code table
28
+ * ---------------
29
+ *
30
+ * - `0` success.
31
+ * - `1` user error — bad flag, missing required flag, invalid JSON,
32
+ * validation failure on user input, unknown verb/subverb/host.
33
+ * - `2` runtime/state error — store conflict or business-rule failure
34
+ * (negotiation not found, already open, already stabilized, signature
35
+ * fails verification, quorum incomplete, broken journal, divergent
36
+ * pre-existing config file).
37
+ * - `3` I/O / OS error — file unreadable, permission denied, write
38
+ * refused by the filesystem.
39
+ *
40
+ * DEC-034 freezes this contract. Future breaking changes require a new DEC
41
+ * and a major version bump on `@sentropic/h2a-cli`.
42
+ */
43
+ export const H2A_CLI_VERB_CONTRACTS = [
44
+ // --- meta / help ---
45
+ {
46
+ verb: "--help",
47
+ outputShape: "text",
48
+ exitCodes: [0],
49
+ requiredFlags: [],
50
+ optionalFlags: [],
51
+ description: "Print human-readable usage. Same as `help` and no-argv invocation."
52
+ },
53
+ // --- registry / hosts / tooling discovery ---
54
+ {
55
+ verb: "hosts",
56
+ outputShape: "list",
57
+ exitCodes: [0],
58
+ requiredFlags: [],
59
+ optionalFlags: [],
60
+ description: "List host descriptors known to this CLI (codex, claude, gemini)."
61
+ },
62
+ {
63
+ verb: "mcp-tools",
64
+ outputShape: "list",
65
+ exitCodes: [0],
66
+ requiredFlags: [],
67
+ optionalFlags: [],
68
+ description: "List canonical MCP tool names exposed by the built-in server."
69
+ },
70
+ // --- setup / registry ---
71
+ {
72
+ verb: "init",
73
+ outputShape: "action",
74
+ exitCodes: [0, 1, 3],
75
+ requiredFlags: [],
76
+ optionalFlags: ["root"],
77
+ description: "Create the `<root>/.h2a/` local-files store layout (DEC-031)."
78
+ },
79
+ {
80
+ verb: "register",
81
+ outputShape: "action",
82
+ exitCodes: [0, 1, 2],
83
+ requiredFlags: ["json"],
84
+ optionalFlags: ["root"],
85
+ description: "Append an H2AActorRegistration to `registry/instances.jsonl`."
86
+ },
87
+ {
88
+ verb: "discover",
89
+ outputShape: "list",
90
+ exitCodes: [0, 1],
91
+ requiredFlags: [],
92
+ optionalFlags: ["root", "role", "scope"],
93
+ description: "List registered instances, optionally filtered by role/scope."
94
+ },
95
+ // --- negotiation ---
96
+ {
97
+ verb: "negotiate open",
98
+ outputShape: "resource",
99
+ exitCodes: [0, 1, 2],
100
+ requiredFlags: ["json"],
101
+ optionalFlags: ["root"],
102
+ description: "Open a new negotiation, persisting its `state.json`."
103
+ },
104
+ {
105
+ verb: "negotiate status",
106
+ outputShape: "resource",
107
+ exitCodes: [0, 1, 2],
108
+ requiredFlags: ["id", "status"],
109
+ optionalFlags: ["root"],
110
+ description: "Transition a negotiation to a new status (draft / proposed / countered / stabilized / closed)."
111
+ },
112
+ {
113
+ verb: "negotiate event",
114
+ outputShape: "resource",
115
+ exitCodes: [0, 1, 2],
116
+ requiredFlags: ["id", "json"],
117
+ optionalFlags: ["root", "causation-id", "correlation-id"],
118
+ description: "Append an arbitrary event payload to the negotiation journal."
119
+ },
120
+ {
121
+ verb: "negotiate offer",
122
+ outputShape: "resource",
123
+ exitCodes: [0, 1, 2],
124
+ requiredFlags: ["id", "instance", "artifact"],
125
+ optionalFlags: ["root", "event-id", "causation-id", "correlation-id"],
126
+ description: "Append a `propose` journal entry carrying the offered artifact body."
127
+ },
128
+ {
129
+ verb: "negotiate counter",
130
+ outputShape: "resource",
131
+ exitCodes: [0, 1, 2],
132
+ requiredFlags: ["id", "instance", "artifact"],
133
+ optionalFlags: ["root", "event-id", "causation-id", "correlation-id"],
134
+ description: "Append a `counter` journal entry carrying a counter-offer artifact body."
135
+ },
136
+ {
137
+ verb: "negotiate sign",
138
+ outputShape: "resource",
139
+ exitCodes: [0, 1, 2, 3],
140
+ requiredFlags: ["id", "instance", "artifact", "private-key"],
141
+ optionalFlags: ["root", "event-id", "causation-id", "correlation-id"],
142
+ description: "Sign the canonical artifact hash with the given ed25519 PEM private key and append a signature event."
143
+ },
144
+ {
145
+ verb: "negotiate stabilize",
146
+ outputShape: "action",
147
+ exitCodes: [0, 1, 2],
148
+ requiredFlags: ["id"],
149
+ optionalFlags: ["root", "event-id"],
150
+ description: "Verify quorum + signatures, persist the winning artifact in write-once form (DEC-033), and mark the negotiation stabilized."
151
+ },
152
+ {
153
+ verb: "negotiate journal",
154
+ outputShape: "list",
155
+ exitCodes: [0, 1, 2],
156
+ requiredFlags: ["id"],
157
+ optionalFlags: ["root"],
158
+ description: "Read and verify the full hash-chained journal for a negotiation."
159
+ },
160
+ // --- mailboxes ---
161
+ {
162
+ verb: "inbox put",
163
+ outputShape: "action",
164
+ exitCodes: [0, 1, 2],
165
+ requiredFlags: ["instance", "json"],
166
+ optionalFlags: ["root"],
167
+ description: "Drop an H2A envelope into the inbox of an instance."
168
+ },
169
+ {
170
+ verb: "inbox read",
171
+ outputShape: "list",
172
+ exitCodes: [0, 1],
173
+ requiredFlags: ["instance"],
174
+ optionalFlags: ["root"],
175
+ description: "List the inbox envelopes of an instance (oldest first)."
176
+ },
177
+ {
178
+ verb: "inbox pop",
179
+ outputShape: "resource",
180
+ exitCodes: [0, 1, 2],
181
+ requiredFlags: ["instance", "envelope"],
182
+ optionalFlags: ["root"],
183
+ description: "Remove and return a specific envelope from an instance's inbox."
184
+ },
185
+ {
186
+ verb: "outbox put",
187
+ outputShape: "action",
188
+ exitCodes: [0, 1, 2],
189
+ requiredFlags: ["instance", "json"],
190
+ optionalFlags: ["root"],
191
+ description: "Drop an H2A envelope into the outbox of an instance (append-only)."
192
+ },
193
+ {
194
+ verb: "outbox read",
195
+ outputShape: "list",
196
+ exitCodes: [0, 1],
197
+ requiredFlags: ["instance"],
198
+ optionalFlags: ["root"],
199
+ description: "List the outbox envelopes of an instance (oldest first)."
200
+ },
201
+ // --- store maintenance (DEC-036) ---
202
+ {
203
+ verb: "store migrate",
204
+ outputShape: "action",
205
+ exitCodes: [0, 1],
206
+ requiredFlags: [],
207
+ optionalFlags: ["root", "from", "to", "dry-run"],
208
+ description: "Migrate the local-files store schema between known versions (DEC-036). V1→V1 is a no-op (`changed:false`). Unknown --from or --to → exit 1."
209
+ },
210
+ // --- MCP transport ---
211
+ {
212
+ verb: "mcp-serve",
213
+ outputShape: "stream",
214
+ exitCodes: [0, 1],
215
+ requiredFlags: [],
216
+ optionalFlags: ["root"],
217
+ description: "Run the built-in MCP server speaking JSON-RPC 2.0 over stdio (long-running)."
218
+ },
219
+ // --- host wiring ---
220
+ {
221
+ verb: "host setup",
222
+ outputShape: "resource",
223
+ exitCodes: [0, 1, 2, 3],
224
+ requiredFlags: ["host"],
225
+ optionalFlags: ["root", "print", "write", "force"],
226
+ description: "Render or merge the `mcpServers.h2a` snippet for a host (codex|claude). `--print` (default) emits the snippet as a resource on stdout; `--write <file>` switches the verb to an action envelope and merges/creates the target config file."
227
+ },
228
+ {
229
+ verb: "host status",
230
+ outputShape: "action",
231
+ exitCodes: [0, 1],
232
+ requiredFlags: [],
233
+ optionalFlags: ["host"],
234
+ description: "Report each host's wave + adapter/setup/scenario-shipped flags (DEC-037/044). Output is `{ ok: true, hosts: [{host, wave, mcpAdapterShipped, hostSetupShipped, hostScenarioShipped, summary}] }`. Filter to a single host with `--host <name>`; unknown host → exit 1."
235
+ }
236
+ ];
237
+ /** Map of verb-path → contract for O(1) lookups in tests and tooling. */
238
+ export const H2A_CLI_VERB_CONTRACT_BY_VERB = new Map(H2A_CLI_VERB_CONTRACTS.map((c) => [c.verb, c]));
239
+ //# sourceMappingURL=cli-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-contract.js","sourceRoot":"","sources":["../src/cli-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAqBH,MAAM,CAAC,MAAM,sBAAsB,GAAkC;IACnE,sBAAsB;IACtB;QACE,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,MAAM;QACnB,SAAS,EAAE,CAAC,CAAC,CAAC;QACd,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,EAAE;QACjB,WAAW,EAAE,oEAAoE;KAClF;IAED,+CAA+C;IAC/C;QACE,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,MAAM;QACnB,SAAS,EAAE,CAAC,CAAC,CAAC;QACd,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,EAAE;QACjB,WAAW,EAAE,kEAAkE;KAChF;IACD;QACE,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,MAAM;QACnB,SAAS,EAAE,CAAC,CAAC,CAAC;QACd,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,EAAE;QACjB,WAAW,EAAE,+DAA+D;KAC7E;IAED,2BAA2B;IAC3B;QACE,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACpB,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,CAAC,MAAM,CAAC;QACvB,WAAW,EAAE,+DAA+D;KAC7E;IACD;QACE,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACpB,aAAa,EAAE,CAAC,MAAM,CAAC;QACvB,aAAa,EAAE,CAAC,MAAM,CAAC;QACvB,WAAW,EA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B,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACjB,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,CAAC,MAAM,CAAC;QACvB,WAAW,EAAE,8EAA8E;KAC5F;IAED,sBAAsB;IACtB;QACE,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,UAAU;QACvB,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACvB,aAAa,EAAE,CAAC,MAAM,CAAC;QACvB,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;QAClD,WAAW,EACT,4OAA4O;KAC/O;IACD;QACE,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACjB,aAAa,EAAE,EAAE;QACjB,aAAa,EAAE,CAAC,MAAM,CAAC;QACvB,WAAW,EACT,wQAAwQ;KAC3Q;CACO,CAAC;AAEX,yEAAyE;AACzE,MAAM,CAAC,MAAM,6BAA6B,GAA4C,IAAI,GAAG,CAC3F,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAC/C,CAAC"}
package/dist/cli.d.ts CHANGED
@@ -1,7 +1,58 @@
1
+ /**
2
+ * `h2a` CLI dispatcher — stable JSON output contract + exit-code table (DEC-034).
3
+ *
4
+ * Output shapes
5
+ * -------------
6
+ * Every JSON-emitting verb writes ONE of three canonical envelopes on stdout:
7
+ *
8
+ * - **resource** — bare JSON of a single entity. Used by verbs that return the
9
+ * persisted/loaded record itself (`negotiate open`, `negotiate status`,
10
+ * `negotiate event`, `negotiate offer`, `negotiate counter`, `negotiate sign`,
11
+ * `inbox pop`, `host setup --print`).
12
+ * - **list** — bare JSON array. Used by `hosts`, `mcp-tools`, `discover`,
13
+ * `inbox read`, `outbox read`, `negotiate journal`.
14
+ * - **action** — `{ ok: true, ...details }` confirmation envelope. Used by
15
+ * verbs that perform side effects without a natural entity to return
16
+ * (`init`, `register`, `inbox put`, `outbox put`, `negotiate stabilize`,
17
+ * `host setup --write`).
18
+ *
19
+ * Stderr lines always follow `h2a <verb> [sub]: <message>` so callers can
20
+ * grep them deterministically. The `mcp-serve` verb is a long-running
21
+ * JSON-RPC 2.0 stdio transport and does not fit the envelope contract.
22
+ *
23
+ * Exit codes
24
+ * ----------
25
+ *
26
+ * - `0` — success.
27
+ * - `1` — user error: missing/bad flag, invalid JSON, validation failure on
28
+ * caller-supplied data, unknown verb/subverb/host.
29
+ * - `2` — runtime/state error: store conflict or business-rule violation
30
+ * (negotiation not found, already open, already stabilized, signature
31
+ * fails verification, quorum incomplete, broken journal, divergent
32
+ * pre-existing config file refusing merge without `--force`).
33
+ * - `3` — I/O / OS error: file unreadable, permission denied, write
34
+ * refused by the filesystem.
35
+ *
36
+ * The full machine-readable manifest lives in `./cli-contract.ts`
37
+ * (`H2A_CLI_VERB_CONTRACTS`). Human-readable reference: `docs/cli-contract.md`.
38
+ */
1
39
  export interface H2ACliStreams {
2
40
  stderr: Pick<typeof process.stderr, "write">;
3
41
  stdout: Pick<typeof process.stdout, "write">;
42
+ cwd?: () => string;
4
43
  }
5
44
  export declare function renderCliHelp(): string;
45
+ /**
46
+ * `h2a mcp-serve` binds directly to the real process std streams because it
47
+ * is a long-running JSON-RPC loop. The test-friendly `streams` interface
48
+ * (write-only) cannot express a readable stdin; tests cover `runMcpStdio`
49
+ * with `PassThrough` streams instead of going through this verb.
50
+ */
51
+ export declare function runMcpServe(flags: Record<string, string>, io?: {
52
+ stdin: NodeJS.ReadableStream;
53
+ stdout: NodeJS.WritableStream;
54
+ stderr: NodeJS.WritableStream;
55
+ cwd?: () => string;
56
+ }): Promise<number>;
6
57
  export declare function runCli(argv?: readonly string[], streams?: H2ACliStreams): number;
7
58
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,IAAI,CAAC,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,MAAM,EAAE,IAAI,CAAC,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C;AAQD,wBAAgB,aAAa,IAAI,MAAM,CActC;AAED,wBAAgB,MAAM,CACpB,IAAI,GAAE,SAAS,MAAM,EAA0B,EAC/C,OAAO,GAAE,aAGR,GACA,MAAM,CAqBR"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AA0CH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,IAAI,CAAC,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,MAAM,EAAE,IAAI,CAAC,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAQD,wBAAgB,aAAa,IAAI,MAAM,CAwCtC;AAsaD;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,EAAE,GAAE;IACF,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAKpB,GACA,OAAO,CAAC,MAAM,CAAC,CAejB;AA0RD,wBAAgB,MAAM,CACpB,IAAI,GAAE,SAAS,MAAM,EAA0B,EAC/C,OAAO,GAAE,aAGR,GACA,MAAM,CA8BR"}