@alpacakit/agents-conventions 0.1.0-beta.37 → 0.2.0-beta.2

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/README.md CHANGED
@@ -74,10 +74,11 @@ const result = await loginManagedHome({
74
74
 
75
75
  ## `@alpacakit/agents-conventions/cli`
76
76
 
77
- The `agent` command surface, as **data** — no `bin`, no handler, no I/O. It
78
- owns the command paths, the flags, the projection into a procedure input, and
79
- the JSON each result must be, so `alpacaloop agent login` and
80
- `promptopt agent login` are the same command.
77
+ The shared `agent` Endpoint tree — no `bin`, parser, output writer, or startup
78
+ I/O. It owns the command paths, flags, procedure-input projection, and five
79
+ thin procedure handlers, so `alpacaloop agent login` and
80
+ `promptopt agent login` execute the same operation. Collecting the tree and
81
+ rendering help do not open the agents home, keyring, login process, or stdin.
81
82
 
82
83
  ```
83
84
  agent list
@@ -88,31 +89,43 @@ agent add <ID> --kind openai-compatible --base-url <URL> --model <M>
88
89
  agent remove <NAME>
89
90
  ```
90
91
 
91
- Mount the node in the product's tree and bind a handler per endpoint — call the
92
- procedure, render the result:
92
+ Mount the node in the product's tree. The host parser passes only explicitly
93
+ supplied canonical parameter names to `parseOptions`; after it succeeds, the
94
+ host supplies an invocation-scoped `AgentEntryContext` and calls the collected
95
+ handler directly:
93
96
 
94
97
  ```ts
95
- import { AGENT_CLI_SURFACE } from "@alpacakit/agents-conventions/cli";
96
- import { loginManagedHome } from "@alpacakit/agents-conventions";
97
- import { handleCliEndpoint } from "@alpacakit/channels/cli";
98
-
99
- // 1. mount: put AGENT_CLI_SURFACE.node among the product root's children.
100
- // 2. bind:
101
- handleCliEndpoint(AGENT_CLI_SURFACE.endpoints.login, async ({ projection }) =>
102
- render(await loginManagedHome({ ...projection, homeDir, env })),
103
- );
98
+ import {
99
+ AGENT_CLI_SURFACE,
100
+ type AgentEntryContext,
101
+ } from "@alpacakit/agents-conventions/cli";
102
+ import { collectCliCommands } from "@alpacakit/channels/cli";
103
+
104
+ const view = collectCliCommands(AGENT_CLI_SURFACE.node);
105
+ // During host action registration, for each collected command:
106
+ const input = command.input.parseOptions(explicitCanonicalValues);
107
+ const outcome = await command.handler(input, context satisfies AgentEntryContext);
108
+ render(outcome); // text, JSON envelope, redaction, and exit status are host-owned
104
109
  ```
105
110
 
106
- Each endpoint's projection is the matching procedure's input verbatim, so the
107
- handler never re-maps fields: `endpoints.add` projects `{ kind, id, baseUrl,
108
- model, apiKeyEnv?, engine? }` straight into `addAgentConfig`. Optional flags
109
- stay absent when unset — `--engine` is defaulted once, by the agent-config
110
- payload that persists it, never a second time by the command surface. The addable kinds
111
- (`AGENT_ADD_KIND`) live on the root export, next to the procedure that acts on
112
- them — `/cli` only spells them as a flag.
113
-
114
- `AGENT_CLI_SURFACE.outputs` carries the same contracts for products that emit
115
- machine-readable output.
111
+ `AgentEntryContext` contains `{ homeDir, env, ports?, keyring?,
112
+ readCredentialSecret, onLoginEvent, signal? }`. `onLoginEvent` receives the
113
+ typed `LoginEvent`; the host decides how to display it. `--stdin` identifies
114
+ the input source: only the credential-add handler calls
115
+ `readCredentialSecret()`, once, after input validation succeeds.
116
+
117
+ Each handler returns `AgentEntryOutcome`, discriminated by the corresponding
118
+ `AGENT_ENTRY_NAME` in `operation`, with the unchanged procedure result in
119
+ `result`. This is not a CLI text/JSON envelope and carries no exit or
120
+ presentation policy. Optional flags stay absent when unset — `--engine` is
121
+ defaulted once by the persisted agent-config payload. The addable kinds
122
+ (`AGENT_ADD_KIND`) remain on the root export beside the procedure that acts on
123
+ them; `/cli` only spells them as a flag.
124
+
125
+ `AGENT_CLI_SURFACE.outputs.<operation>.schema` remains the explicit validator
126
+ for the inner procedure result used by existing projectors. It intentionally
127
+ does not validate the tagged `AgentEntryOutcome` wrapper; presentation code
128
+ selects the operation and validates `outcome.result` when required.
116
129
 
117
130
  `@alpacakit/channels` and `zod` are **peer** dependencies of this package: they
118
131
  are needed only by `/cli`, so importing the procedures never drags a CLI
@@ -8,8 +8,8 @@ import { AGENT_AVAILABILITY_STATUS, AGENT_INDETERMINATE_REASON, AGENT_UNAVAILABL
8
8
  import { CANDIDATE_SOURCE_KIND } from "@alpacakit/agents/config";
9
9
  import { jsonValueSchema } from "@alpacakit/core";
10
10
  import { z } from "zod";
11
- import { ADD_AGENT_CONFIG_RESULT, ADD_API_KEY_PROFILE_RESULT, LOGIN_MANAGED_HOME_RESULT, } from "./register.js";
12
11
  import { INVALID_NAME_RESULT_KIND } from "./names.js";
12
+ import { ADD_AGENT_CONFIG_RESULT, ADD_API_KEY_PROFILE_RESULT, LOGIN_MANAGED_HOME_RESULT, } from "./register.js";
13
13
  import { REMOVE_AGENTS_HOME_ENTRY_RESULT } from "./remove.js";
14
14
  const RESULT_DISCRIMINATOR = "kind";
15
15
  const AVAILABILITY_DISCRIMINATOR = "status";