@cotal-ai/workspace 0.90.1 → 0.92.0
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/build/Release/win32-arm64/build.json +1 -1
- package/build/Release/win32-x64/build.json +2 -2
- package/build/Release/win32-x64/creation.node +0 -0
- package/dist/agent-secrets.d.ts +2 -2
- package/dist/agent-secrets.d.ts.map +1 -1
- package/dist/agent-secrets.js +2 -2
- package/dist/agent-secrets.js.map +1 -1
- package/dist/auth-paths.d.ts +8 -2
- package/dist/auth-paths.d.ts.map +1 -1
- package/dist/auth-paths.js +12 -5
- package/dist/auth-paths.js.map +1 -1
- package/dist/broker-display.d.ts +4 -0
- package/dist/broker-display.d.ts.map +1 -0
- package/dist/broker-display.js +29 -0
- package/dist/broker-display.js.map +1 -0
- package/dist/colors.d.ts +11 -4
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +36 -9
- package/dist/colors.js.map +1 -1
- package/dist/connect.d.ts +81 -10
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +195 -75
- package/dist/connect.js.map +1 -1
- package/dist/control-target.d.ts +2 -2
- package/dist/control-target.d.ts.map +1 -1
- package/dist/control-target.js +13 -5
- package/dist/control-target.js.map +1 -1
- package/dist/credential-actions.d.ts +91 -0
- package/dist/credential-actions.d.ts.map +1 -0
- package/dist/credential-actions.js +74 -0
- package/dist/credential-actions.js.map +1 -0
- package/dist/deprecated-daemon-entries.d.ts +30 -0
- package/dist/deprecated-daemon-entries.d.ts.map +1 -0
- package/dist/deprecated-daemon-entries.js +37 -0
- package/dist/deprecated-daemon-entries.js.map +1 -0
- package/dist/endpoint-actions.d.ts +31 -0
- package/dist/endpoint-actions.d.ts.map +1 -0
- package/dist/endpoint-actions.js +2 -0
- package/dist/endpoint-actions.js.map +1 -0
- package/dist/endpoint-caller.d.ts +74 -0
- package/dist/endpoint-caller.d.ts.map +1 -0
- package/dist/endpoint-caller.js +118 -0
- package/dist/endpoint-caller.js.map +1 -0
- package/dist/endpoint-contract.d.ts +32 -0
- package/dist/endpoint-contract.d.ts.map +1 -0
- package/dist/endpoint-contract.js +92 -0
- package/dist/endpoint-contract.js.map +1 -0
- package/dist/extension-mutation.d.ts.map +1 -1
- package/dist/extension-mutation.js +4 -1
- package/dist/extension-mutation.js.map +1 -1
- package/dist/extensions.d.ts +28 -8
- package/dist/extensions.d.ts.map +1 -1
- package/dist/extensions.js +20 -8
- package/dist/extensions.js.map +1 -1
- package/dist/flags.d.ts +8 -1
- package/dist/flags.d.ts.map +1 -1
- package/dist/flags.js +9 -7
- package/dist/flags.js.map +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/dist/launch-persona.d.ts +10 -0
- package/dist/launch-persona.d.ts.map +1 -0
- package/dist/launch-persona.js +34 -0
- package/dist/launch-persona.js.map +1 -0
- package/dist/local-process.d.ts +60 -12
- package/dist/local-process.d.ts.map +1 -1
- package/dist/local-process.js +173 -4
- package/dist/local-process.js.map +1 -1
- package/dist/maintenance.d.ts +267 -4
- package/dist/maintenance.d.ts.map +1 -1
- package/dist/maintenance.js +666 -12
- package/dist/maintenance.js.map +1 -1
- package/dist/mesh-manifest-schema.d.ts +118 -0
- package/dist/mesh-manifest-schema.d.ts.map +1 -0
- package/dist/mesh-manifest-schema.js +96 -0
- package/dist/mesh-manifest-schema.js.map +1 -0
- package/dist/mesh-registry.d.ts +30 -0
- package/dist/mesh-registry.d.ts.map +1 -1
- package/dist/mesh-registry.js +74 -13
- package/dist/mesh-registry.js.map +1 -1
- package/dist/mesh-target.d.ts +15 -7
- package/dist/mesh-target.d.ts.map +1 -1
- package/dist/mesh-target.js +77 -26
- package/dist/mesh-target.js.map +1 -1
- package/dist/official-connectors.d.ts +13 -0
- package/dist/official-connectors.d.ts.map +1 -1
- package/dist/official-connectors.js +18 -2
- package/dist/official-connectors.js.map +1 -1
- package/dist/output.d.ts +147 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +186 -0
- package/dist/output.js.map +1 -0
- package/dist/pid.d.ts +5 -3
- package/dist/pid.d.ts.map +1 -1
- package/dist/pid.js +25 -13
- package/dist/pid.js.map +1 -1
- package/dist/preferences.d.ts +93 -0
- package/dist/preferences.d.ts.map +1 -0
- package/dist/preferences.js +272 -0
- package/dist/preferences.js.map +1 -0
- package/dist/preflight.d.ts +3 -0
- package/dist/preflight.d.ts.map +1 -1
- package/dist/preflight.js +6 -3
- package/dist/preflight.js.map +1 -1
- package/dist/prepared-spaces.d.ts +27 -0
- package/dist/prepared-spaces.d.ts.map +1 -0
- package/dist/prepared-spaces.js +57 -0
- package/dist/prepared-spaces.js.map +1 -0
- package/dist/present.d.ts +108 -0
- package/dist/present.d.ts.map +1 -0
- package/dist/present.js +249 -0
- package/dist/present.js.map +1 -0
- package/dist/prompt-input.d.ts +12 -0
- package/dist/prompt-input.d.ts.map +1 -0
- package/dist/prompt-input.js +35 -0
- package/dist/prompt-input.js.map +1 -0
- package/dist/protected-records.d.ts +102 -0
- package/dist/protected-records.d.ts.map +1 -0
- package/dist/protected-records.js +465 -0
- package/dist/protected-records.js.map +1 -0
- package/dist/registration-policy.d.ts +4 -1
- package/dist/registration-policy.d.ts.map +1 -1
- package/dist/registration-policy.js +4 -3
- package/dist/registration-policy.js.map +1 -1
- package/dist/render.d.ts +8 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +49 -32
- package/dist/render.js.map +1 -1
- package/dist/renewal-path.d.ts +5 -0
- package/dist/renewal-path.d.ts.map +1 -0
- package/dist/renewal-path.js +9 -0
- package/dist/renewal-path.js.map +1 -0
- package/dist/renewal.d.ts +6 -9
- package/dist/renewal.d.ts.map +1 -1
- package/dist/renewal.js +7 -12
- package/dist/renewal.js.map +1 -1
- package/dist/service-adapter.d.ts +201 -0
- package/dist/service-adapter.d.ts.map +1 -0
- package/dist/service-adapter.js +294 -0
- package/dist/service-adapter.js.map +1 -0
- package/dist/service-custody.d.ts +5 -0
- package/dist/service-custody.d.ts.map +1 -0
- package/dist/service-custody.js +41 -0
- package/dist/service-custody.js.map +1 -0
- package/dist/service-definition.d.ts +52 -0
- package/dist/service-definition.d.ts.map +1 -0
- package/dist/service-definition.js +85 -0
- package/dist/service-definition.js.map +1 -0
- package/dist/service-definition.schema.json +79 -0
- package/dist/service-extension-metadata.d.ts +11 -0
- package/dist/service-extension-metadata.d.ts.map +1 -0
- package/dist/service-extension-metadata.js +66 -0
- package/dist/service-extension-metadata.js.map +1 -0
- package/dist/service-identity.d.ts +51 -0
- package/dist/service-identity.d.ts.map +1 -0
- package/dist/service-identity.js +103 -0
- package/dist/service-identity.js.map +1 -0
- package/dist/service-observation.d.ts +32 -0
- package/dist/service-observation.d.ts.map +1 -0
- package/dist/service-observation.js +134 -0
- package/dist/service-observation.js.map +1 -0
- package/dist/service-preset.d.ts +12 -0
- package/dist/service-preset.d.ts.map +1 -0
- package/dist/service-preset.js +10 -0
- package/dist/service-preset.js.map +1 -0
- package/dist/service-startup.d.ts +23 -0
- package/dist/service-startup.d.ts.map +1 -0
- package/dist/service-startup.js +39 -0
- package/dist/service-startup.js.map +1 -0
- package/dist/service-stop.d.ts +47 -0
- package/dist/service-stop.d.ts.map +1 -0
- package/dist/service-stop.js +152 -0
- package/dist/service-stop.js.map +1 -0
- package/dist/service-target.d.ts +5 -0
- package/dist/service-target.d.ts.map +1 -0
- package/dist/service-target.js +19 -0
- package/dist/service-target.js.map +1 -0
- package/dist/signer-export.d.ts +31 -0
- package/dist/signer-export.d.ts.map +1 -0
- package/dist/signer-export.js +114 -0
- package/dist/signer-export.js.map +1 -0
- package/dist/space-segmentation.d.ts +21 -7
- package/dist/space-segmentation.d.ts.map +1 -1
- package/dist/space-segmentation.js +26 -9
- package/dist/space-segmentation.js.map +1 -1
- package/dist/space.d.ts +5 -5
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +8 -6
- package/dist/space.js.map +1 -1
- package/dist/system-rotation.d.ts +4 -3
- package/dist/system-rotation.d.ts.map +1 -1
- package/dist/system-rotation.js +16 -6
- package/dist/system-rotation.js.map +1 -1
- package/dist/web-session.d.ts +7 -0
- package/dist/web-session.d.ts.map +1 -1
- package/dist/web-session.js +9 -0
- package/dist/web-session.js.map +1 -1
- package/package.json +6 -2
package/dist/connect.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { type EpCaller, type MintOpts, type Profile, type SpaceAuth } from "@cotal-ai/core";
|
|
1
|
+
import { type IssuedCaller, type EpCaller, type MintOpts, type Profile, type SpaceAuth } from "@cotal-ai/core";
|
|
2
2
|
import { type UserAuthInfo } from "./mesh-registry.js";
|
|
3
3
|
import { type MeshTarget, type ResolveFlags } from "./mesh-target.js";
|
|
4
|
+
import { type WorkspaceErrorParts } from "./render.js";
|
|
5
|
+
import { CommandFailure, type RefusalCode } from "./output.js";
|
|
6
|
+
import type { MeshTargetErrorCode } from "./mesh-target.js";
|
|
7
|
+
import type { PreflightFailure } from "./preflight.js";
|
|
4
8
|
/**
|
|
5
9
|
* The one way every command that touches a running mesh figures out WHICH mesh + with what creds,
|
|
6
10
|
* and confirms it's actually up — shared by every command surface (@cotal-ai/cli, @cotal-ai/web)
|
|
@@ -22,6 +26,8 @@ export interface ConnectFlags extends ResolveFlags {
|
|
|
22
26
|
export interface ConnectOpts {
|
|
23
27
|
instanceId?: string | string[];
|
|
24
28
|
mint?: Pick<MintOpts, "runDriver" | "runMediator" | "runOperator" | "runAdmitter">;
|
|
29
|
+
/** A read must not sweep or prune the local registry as a hidden prelude. */
|
|
30
|
+
readOnly?: boolean;
|
|
25
31
|
}
|
|
26
32
|
/** Raw NATS auth for an off-registry connection — a join link / --token / --user+--pass / --creds.
|
|
27
33
|
* Structurally matches what `probeConnect` accepts. */
|
|
@@ -142,6 +148,14 @@ export declare function userSessionAuth(target: {
|
|
|
142
148
|
bearer: string;
|
|
143
149
|
sentinelCreds: string;
|
|
144
150
|
}>;
|
|
151
|
+
/** {@link userViewAuth} with the provider's own failure classified, as {@link userConnectOrThrow}
|
|
152
|
+
* classifies the bearer's. A refused, signed-out or unanswered exchange happens before any request,
|
|
153
|
+
* so it is a {@link ConnectRefusal} under its code, not an unclassified error that a structured
|
|
154
|
+
* command must report as unknown. Only signed-out is `permanent`. `cotal attach` mints this view
|
|
155
|
+
* again on every reconnect, an exchange that did not answer may answer the next time, and the
|
|
156
|
+
* provider reports every answered failure as refused, including a manager that is not live yet and
|
|
157
|
+
* a registry read that failed. Any other error rethrows unchanged. */
|
|
158
|
+
export declare function userViewAuthOrThrow(conn: Connection, view: string, opts?: Parameters<typeof userViewAuth>[2]): Promise<UserViewAuth>;
|
|
145
159
|
/** {@link userViewAuth}, workstation-flavoured: colour the thrown sentence and exit. */
|
|
146
160
|
export declare function userViewAuthOrExit(conn: Connection, view: string): Promise<UserViewAuth>;
|
|
147
161
|
/** Fail-closed guard for the flip: explicit raw creds are still useful for true off-registry/static
|
|
@@ -164,21 +178,70 @@ export declare function refuseStaticCredsForKnownUserAuthOrExit(space: string, s
|
|
|
164
178
|
* wrapper that supplies the exiting disposition. The two forms cannot drift in what they say
|
|
165
179
|
* because there is only one place the sentence is written.
|
|
166
180
|
*
|
|
167
|
-
* `kind` says whether asking again can help. `transient` is a broker that did not answer in time
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
181
|
+
* `kind` says whether asking again can help. `transient` is a broker that did not answer in time or
|
|
182
|
+
* could not be reached, or a view exchange that failed for any reason but a sign-out (see
|
|
183
|
+
* {@link userViewAuthOrThrow}): a caller that keeps going retries it. Every other refusal is
|
|
184
|
+
* `permanent` (missing seed, refused credentials, a user-auth mesh offered static creds), and a
|
|
185
|
+
* caller that keeps going must stop and say the sentence rather than retry it.
|
|
171
186
|
*/
|
|
172
187
|
export type ConnectRefusalKind = "transient" | "permanent";
|
|
188
|
+
declare const REFUSAL_BRAND: unique symbol;
|
|
173
189
|
export declare class ConnectRefusal extends Error {
|
|
174
190
|
readonly rendered: string;
|
|
175
|
-
readonly hint
|
|
191
|
+
readonly hint: string | undefined;
|
|
192
|
+
/** A brand that survives two copies of this module, where `instanceof` would not. */
|
|
193
|
+
readonly [REFUSAL_BRAND] = true;
|
|
176
194
|
readonly kind: ConnectRefusalKind;
|
|
177
|
-
|
|
195
|
+
/** The stable code a structured command reports this refusal under (`AUTH_REQUIRED`,
|
|
196
|
+
* `TARGET_UNAVAILABLE`, ...). Every refusal names one, so none reaches a script unclassified. */
|
|
197
|
+
readonly code: RefusalCode;
|
|
198
|
+
/** The sentence as its message and remedy, when it was written in two parts. */
|
|
199
|
+
readonly parts: WorkspaceErrorParts | undefined;
|
|
200
|
+
constructor(rendered: string, hint: string | undefined, options: {
|
|
178
201
|
cause?: unknown;
|
|
179
202
|
kind?: ConnectRefusalKind;
|
|
203
|
+
code: RefusalCode;
|
|
204
|
+
parts?: WorkspaceErrorParts;
|
|
180
205
|
});
|
|
206
|
+
/** This refusal as a command's classified failure under its code: the message, and the remedy
|
|
207
|
+
* apart from it. */
|
|
208
|
+
failure(): CommandFailure;
|
|
181
209
|
}
|
|
210
|
+
export declare function isConnectRefusal(e: unknown): e is ConnectRefusal;
|
|
211
|
+
/** The stable code for a mesh target that cannot be resolved. */
|
|
212
|
+
export declare function targetErrorCode(code: MeshTargetErrorCode): RefusalCode;
|
|
213
|
+
/** The stable code for a preflight that did not connect: an outage, a credential the broker needs
|
|
214
|
+
* or a fresh one, or a credential it refused. */
|
|
215
|
+
export declare function preflightCode(failure: PreflightFailure): RefusalCode;
|
|
216
|
+
/** Why a user-auth provider could not issue credentials, when it says: no sign-in session
|
|
217
|
+
* (`signed-out`), its service did not answer (`unavailable`), or it answered and refused this actor
|
|
218
|
+
* (`refused`). A provider sets it as the thrown error's `code`; anything else is unclassified. */
|
|
219
|
+
export type CredentialFailure = "signed-out" | "unavailable" | "refused";
|
|
220
|
+
/** An error a user-auth provider throws, carrying its {@link CredentialFailure}. */
|
|
221
|
+
export declare function credentialFailure(code: CredentialFailure, message: string): Error;
|
|
222
|
+
/** The provider's own sentence when it answered and refused this actor, such as the scope an elevated
|
|
223
|
+
* view needs and the whole-row re-grant that adds it, shown on one line. Undefined for any other
|
|
224
|
+
* error. */
|
|
225
|
+
export declare function credentialRefusalMessage(e: unknown): string | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* Mint one control-caller instrument for a target the caller already resolved. It is an ISSUANCE
|
|
228
|
+
* (SPEC 13.15): its rails carry a fresh generation, and its ceiling is recorded before the material
|
|
229
|
+
* exists. It depends on no lifecycle gate, so its evidence carries the credential's own five-minute
|
|
230
|
+
* expiry as its liveness. Nothing here reads the registry or the `use` selection, so a caller that
|
|
231
|
+
* pinned its target keeps minting against that target after either one changes.
|
|
232
|
+
*
|
|
233
|
+
* `instanceId` pins THIS one-shot instrument to that manager instance, so it is issued the exact
|
|
234
|
+
* `ep.inst.<endpoint>.<iid>.<command>` rows. Without it the instrument holds only class-rail rows,
|
|
235
|
+
* every instance-addressed request is refused at the broker, and the client renders that refusal
|
|
236
|
+
* as a describe timeout, so `--on` reads as an unresponsive manager rather than an unminted grant.
|
|
237
|
+
* The capability SHAPE is core's to define; this site only decides that a pin was asked for.
|
|
238
|
+
*/
|
|
239
|
+
export declare function mintControlInstrument(target: Pick<MeshTarget, "server" | "space" | "tlsRequired"> & {
|
|
240
|
+
readonly auth: SpaceAuth;
|
|
241
|
+
}, tier: "privileged" | "admin", instanceId?: string | string[]): Promise<{
|
|
242
|
+
creds: string;
|
|
243
|
+
epCaller: IssuedCaller;
|
|
244
|
+
}>;
|
|
182
245
|
/**
|
|
183
246
|
* Resolve where a mesh-touching command connects + with what creds, THROWING {@link ConnectRefusal}
|
|
184
247
|
* on every refusal instead of ending the process. {@link connectOrExit} is this plus the printing
|
|
@@ -187,9 +250,16 @@ export declare class ConnectRefusal extends Error {
|
|
|
187
250
|
* per-user-auth mesh. Those refuse static creds fail-closed because old local creds remain
|
|
188
251
|
* broker-valid but are the wrong identity plane after the flip.
|
|
189
252
|
* • Otherwise → resolve the running mesh from the registry (works from any dir), mint `role` creds
|
|
190
|
-
* on an auth mesh, and preflight with the registry's stale-prune.
|
|
253
|
+
* on an auth mesh, and preflight with the registry's stale-prune unless readOnly is requested.
|
|
191
254
|
*/
|
|
192
255
|
export declare function connectOrThrow(flags: ConnectFlags, role: Profile, opts?: ConnectOpts): Promise<Connection>;
|
|
256
|
+
/**
|
|
257
|
+
* Connect to a mesh the caller already resolved, as {@link connectOrThrow} does once it has
|
|
258
|
+
* resolved one: the logged-in user bearer on a user-auth mesh, a minted `role` credential on a
|
|
259
|
+
* static-auth mesh and none on an open one, then a preflight with the registry's stale-prune unless
|
|
260
|
+
* readOnly is requested. It never resolves a target, so a caller that pinned one connects to it.
|
|
261
|
+
*/
|
|
262
|
+
export declare function connectTargetOrThrow(target: MeshTarget, role: Profile, opts?: ConnectOpts): Promise<Connection>;
|
|
193
263
|
/**
|
|
194
264
|
* Connect as the logged-in user on a user-auth mesh. **No profile/role argument** — there is no
|
|
195
265
|
* instrument mint on this path; ledger scope is the grant and `epCaller` comes from the bearer
|
|
@@ -218,12 +288,12 @@ export declare function reachableOrExit(server: string, auth?: RawAuth): Promise
|
|
|
218
288
|
* `--server` override. */
|
|
219
289
|
export declare function resolveTargetOrThrow(flags: ResolveFlags): Promise<MeshTarget>;
|
|
220
290
|
/** Confirm the resolved mesh is up and accepts these creds — replaces the raw NATS "Authorization
|
|
221
|
-
* Violation" trace with one sentence
|
|
291
|
+
* Violation" trace with one sentence. A readOnly caller never prunes the entry on a mismatch.
|
|
222
292
|
* The probe + classify + render live beside this file; this wrapper owns the operator I/O — it
|
|
223
293
|
* acts on the prune decision, colours, and exits. Probes with `probeCreds` when given (the
|
|
224
294
|
* caller's `--creds`/minted creds); otherwise a throwaway identity is minted from the target's
|
|
225
295
|
* own trust material. */
|
|
226
|
-
export declare function preflightOrThrow(target: MeshTarget, probeCreds?: string): Promise<void>;
|
|
296
|
+
export declare function preflightOrThrow(target: MeshTarget, probeCreds?: string, readOnly?: boolean): Promise<void>;
|
|
227
297
|
/** {@link preflightOrThrow} with the exiting disposition. */
|
|
228
298
|
export declare function preflightOrExit(target: MeshTarget, probeCreds?: string): Promise<void>;
|
|
229
299
|
/**
|
|
@@ -233,4 +303,5 @@ export declare function preflightOrExit(target: MeshTarget, probeCreds?: string)
|
|
|
233
303
|
export declare function connectOrExit(flags: ConnectFlags, role: Profile, opts?: ConnectOpts): Promise<Connection>;
|
|
234
304
|
/** {@link resolveTargetOrThrow} with the exiting disposition. */
|
|
235
305
|
export declare function resolveTargetOrExit(flags: ResolveFlags): Promise<MeshTarget>;
|
|
306
|
+
export {};
|
|
236
307
|
//# sourceMappingURL=connect.d.ts.map
|
package/dist/connect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,EAeL,KAAK,YAAY,EAIjB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAA6C,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEjH,OAAO,EAAkE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,YAAa,SAAQ,YAAY;IAChD,gGA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AY,GAAG,OAAO,CAAC,UAAU,CAAC,CAuBvF;AAED;+FAC+F;AAC/F,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAKxF;AAwDD;;mGAEmG;AACnG,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,OAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBxF;AAED,6DAA6D;AAC7D,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,OAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvF;AAED;;;;;;2BAM2B;AAC3B,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAiBnF;AAED;;;;;0BAK0B;AAC1B,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB/G;AAED,6DAA6D;AAC7D,wBAAsB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM5F;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAMnH;AAED,iEAAiE;AACjE,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAMlF"}
|
package/dist/connect.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { DEFAULT_SERVER, DEFAULT_SPACE, DEV_OWNER, assertLifecycleToken, instancePinnedInstrumentCapabilities, isReachable, managerCallerBinding, mintCreds, mintLifecycleUid, mintGeneration, mintAcceptedToken, newIdentity, withIssuerSession, probeConnect, registry, } from "@cotal-ai/core";
|
|
2
|
+
import { DEFAULT_SERVER, DEFAULT_SPACE, DEV_OWNER, assertLifecycleToken, instancePinnedInstrumentCapabilities, isReachable, managerCallerBinding, mintCreds, mintLifecycleUid, mintGeneration, mintAcceptedToken, newIdentity, oneLine, withIssuerSession, probeConnect, registry, } from "@cotal-ai/core";
|
|
3
3
|
import { c } from "./colors.js";
|
|
4
4
|
import { findCotalRoot, hasUserAuthState, userAuthStateDir } from "./auth-paths.js";
|
|
5
5
|
import { workspaceSecretStore } from "./secret-store-fs.js";
|
|
6
|
-
import { findMesh,
|
|
6
|
+
import { findMesh, pruneMesh } from "./mesh-registry.js";
|
|
7
7
|
import { isWorkspaceTargetError, resolveMeshTarget } from "./mesh-target.js";
|
|
8
8
|
import { PREFLIGHT_CONFIRM_TIMEOUT_MS, preflightTarget, pruneStaleMeshes } from "./preflight.js";
|
|
9
|
-
import { renderWorkspaceError } from "./render.js";
|
|
9
|
+
import { renderWorkspaceError, workspaceErrorParts } from "./render.js";
|
|
10
|
+
import { CommandFailure } from "./output.js";
|
|
10
11
|
/** The one way a command turns a {@link Connection} into endpoint auth options — spread this into
|
|
11
12
|
* `new CotalEndpoint({...})` instead of passing `creds:` directly, so a user-mode connection
|
|
12
13
|
* (bearer + sentinel) and a static/raw one (creds) ride the same call sites without each command
|
|
@@ -91,6 +92,24 @@ export async function userSessionAuth(target, sessionGrant) {
|
|
|
91
92
|
});
|
|
92
93
|
return { bearer, sentinelCreds };
|
|
93
94
|
}
|
|
95
|
+
/** {@link userViewAuth} with the provider's own failure classified, as {@link userConnectOrThrow}
|
|
96
|
+
* classifies the bearer's. A refused, signed-out or unanswered exchange happens before any request,
|
|
97
|
+
* so it is a {@link ConnectRefusal} under its code, not an unclassified error that a structured
|
|
98
|
+
* command must report as unknown. Only signed-out is `permanent`. `cotal attach` mints this view
|
|
99
|
+
* again on every reconnect, an exchange that did not answer may answer the next time, and the
|
|
100
|
+
* provider reports every answered failure as refused, including a manager that is not live yet and
|
|
101
|
+
* a registry read that failed. Any other error rethrows unchanged. */
|
|
102
|
+
export async function userViewAuthOrThrow(conn, view, opts = {}) {
|
|
103
|
+
try {
|
|
104
|
+
return await userViewAuth(conn, view, opts);
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
const code = e?.code;
|
|
108
|
+
if (code !== "refused" && code !== "signed-out" && code !== "unavailable")
|
|
109
|
+
throw e;
|
|
110
|
+
throw new ConnectRefusal(`✗ ${e.message}`, undefined, { cause: e, kind: code === "signed-out" ? "permanent" : "transient", code: credentialCode(e) });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
94
113
|
/** {@link userViewAuth}, workstation-flavoured: colour the thrown sentence and exit. */
|
|
95
114
|
export async function userViewAuthOrExit(conn, view) {
|
|
96
115
|
try {
|
|
@@ -132,7 +151,7 @@ export function refuseStaticCredsForKnownUserAuth(space, server, what) {
|
|
|
132
151
|
const knownLocalUser = hasUserAuthState(findCotalRoot(), space);
|
|
133
152
|
if (!knownRecordedUser && !knownLocalUser)
|
|
134
153
|
return;
|
|
135
|
-
throw new ConnectRefusal(`✗ ${what} tried to authenticate with a static creds file, but space "${space}" is a per-user-auth mesh - old --creds files are refused here so they can't bypass user accounts.`, ` Sign in with \`cotal login\` and use the user-mode path instead (for agents: \`cotal spawn\`)
|
|
154
|
+
throw new ConnectRefusal(`✗ ${what} tried to authenticate with a static creds file, but space "${space}" is a per-user-auth mesh - old --creds files are refused here so they can't bypass user accounts.`, ` Sign in with \`cotal login\` and use the user-mode path instead (for agents: \`cotal spawn\`).`, { code: "AUTH_REQUIRED" });
|
|
136
155
|
}
|
|
137
156
|
/** {@link refuseStaticCredsForKnownUserAuth} with the exiting disposition, for the callers that are
|
|
138
157
|
* one command deep and want the refusal to end it. */
|
|
@@ -144,18 +163,98 @@ export function refuseStaticCredsForKnownUserAuthOrExit(space, server, what) {
|
|
|
144
163
|
exitOnRefusal(e);
|
|
145
164
|
}
|
|
146
165
|
}
|
|
166
|
+
const REFUSAL_BRAND = Symbol.for("cotal.ConnectRefusal");
|
|
147
167
|
export class ConnectRefusal extends Error {
|
|
148
168
|
rendered;
|
|
149
169
|
hint;
|
|
170
|
+
/** A brand that survives two copies of this module, where `instanceof` would not. */
|
|
171
|
+
[REFUSAL_BRAND] = true;
|
|
150
172
|
kind;
|
|
173
|
+
/** The stable code a structured command reports this refusal under (`AUTH_REQUIRED`,
|
|
174
|
+
* `TARGET_UNAVAILABLE`, ...). Every refusal names one, so none reaches a script unclassified. */
|
|
175
|
+
code;
|
|
176
|
+
/** The sentence as its message and remedy, when it was written in two parts. */
|
|
177
|
+
parts;
|
|
151
178
|
constructor(rendered, hint, options) {
|
|
152
179
|
super(rendered, options);
|
|
153
180
|
this.rendered = rendered;
|
|
154
181
|
this.hint = hint;
|
|
155
182
|
this.name = "ConnectRefusal";
|
|
156
|
-
this.kind = options
|
|
183
|
+
this.kind = options.kind ?? "permanent";
|
|
184
|
+
this.code = options.code;
|
|
185
|
+
this.parts = options.parts;
|
|
186
|
+
}
|
|
187
|
+
/** This refusal as a command's classified failure under its code: the message, and the remedy
|
|
188
|
+
* apart from it. */
|
|
189
|
+
failure() {
|
|
190
|
+
const remedy = this.parts?.remedy ?? this.hint?.trim();
|
|
191
|
+
return new CommandFailure("refused", this.code, this.parts?.message ?? this.rendered.replace(/^✗ /, ""), remedy ? { remedy } : {});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** A refusal over a workspace failure: the one-line sentence for a terminal, its parts for a
|
|
195
|
+
* structured command. */
|
|
196
|
+
function workspaceRefusal(e, options) {
|
|
197
|
+
return new ConnectRefusal(renderWorkspaceError(e), undefined, { ...options, parts: workspaceErrorParts(e) });
|
|
198
|
+
}
|
|
199
|
+
export function isConnectRefusal(e) {
|
|
200
|
+
return typeof e === "object" && e !== null && e[REFUSAL_BRAND] === true;
|
|
201
|
+
}
|
|
202
|
+
/** The stable code for a mesh target that cannot be resolved. */
|
|
203
|
+
export function targetErrorCode(code) {
|
|
204
|
+
switch (code) {
|
|
205
|
+
case "no-meshes":
|
|
206
|
+
case "unknown-space":
|
|
207
|
+
case "user-auth-unrecorded":
|
|
208
|
+
return "TARGET_NOT_FOUND";
|
|
209
|
+
case "not-started":
|
|
210
|
+
return "TARGET_UNAVAILABLE";
|
|
211
|
+
case "ambiguous-target":
|
|
212
|
+
return "TARGET_AMBIGUOUS";
|
|
213
|
+
case "default-occupied":
|
|
214
|
+
return "CONFLICT";
|
|
215
|
+
case "stale-auth-root":
|
|
216
|
+
case "unreadable-auth":
|
|
217
|
+
return "DEPENDENCY_UNAVAILABLE";
|
|
157
218
|
}
|
|
158
219
|
}
|
|
220
|
+
/** The stable code for a preflight that did not connect: an outage, a credential the broker needs
|
|
221
|
+
* or a fresh one, or a credential it refused. */
|
|
222
|
+
export function preflightCode(failure) {
|
|
223
|
+
switch (failure) {
|
|
224
|
+
case "unreachable":
|
|
225
|
+
case "slow-link":
|
|
226
|
+
return "TARGET_UNAVAILABLE";
|
|
227
|
+
case "registry-open-now-auth":
|
|
228
|
+
case "open-wants-auth":
|
|
229
|
+
case "stale-auth":
|
|
230
|
+
return "AUTH_REQUIRED";
|
|
231
|
+
case "registry-creds-rejected":
|
|
232
|
+
case "creds-rejected":
|
|
233
|
+
return "PERMISSION_DENIED";
|
|
234
|
+
case "tls-trust":
|
|
235
|
+
return "DEPENDENCY_UNAVAILABLE";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/** An error a user-auth provider throws, carrying its {@link CredentialFailure}. */
|
|
239
|
+
export function credentialFailure(code, message) {
|
|
240
|
+
return Object.assign(new Error(message), { code });
|
|
241
|
+
}
|
|
242
|
+
/** The provider's own sentence when it answered and refused this actor, such as the scope an elevated
|
|
243
|
+
* view needs and the whole-row re-grant that adds it, shown on one line. Undefined for any other
|
|
244
|
+
* error. */
|
|
245
|
+
export function credentialRefusalMessage(e) {
|
|
246
|
+
return e instanceof Error && e.code === "refused" ? oneLine(e.message) : undefined;
|
|
247
|
+
}
|
|
248
|
+
function credentialCode(e) {
|
|
249
|
+
const code = e?.code;
|
|
250
|
+
if (code === "signed-out")
|
|
251
|
+
return "AUTH_REQUIRED";
|
|
252
|
+
if (code === "refused")
|
|
253
|
+
return "PERMISSION_DENIED";
|
|
254
|
+
// A provider that cannot issue credentials for a reason it does not name is still a dependency
|
|
255
|
+
// the command could not use; it is not reported as a sign-in the operator could fix.
|
|
256
|
+
return "DEPENDENCY_UNAVAILABLE";
|
|
257
|
+
}
|
|
159
258
|
/** The exiting disposition, in ONE place: print what the refusal already decided to say, and end
|
|
160
259
|
* the command. Anything that is not a {@link ConnectRefusal} is a real fault and rethrows. */
|
|
161
260
|
function exitOnRefusal(e) {
|
|
@@ -166,6 +265,32 @@ function exitOnRefusal(e) {
|
|
|
166
265
|
console.error(c.dim(e.hint));
|
|
167
266
|
process.exit(1);
|
|
168
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Mint one control-caller instrument for a target the caller already resolved. It is an ISSUANCE
|
|
270
|
+
* (SPEC 13.15): its rails carry a fresh generation, and its ceiling is recorded before the material
|
|
271
|
+
* exists. It depends on no lifecycle gate, so its evidence carries the credential's own five-minute
|
|
272
|
+
* expiry as its liveness. Nothing here reads the registry or the `use` selection, so a caller that
|
|
273
|
+
* pinned its target keeps minting against that target after either one changes.
|
|
274
|
+
*
|
|
275
|
+
* `instanceId` pins THIS one-shot instrument to that manager instance, so it is issued the exact
|
|
276
|
+
* `ep.inst.<endpoint>.<iid>.<command>` rows. Without it the instrument holds only class-rail rows,
|
|
277
|
+
* every instance-addressed request is refused at the broker, and the client renders that refusal
|
|
278
|
+
* as a describe timeout, so `--on` reads as an unresponsive manager rather than an unminted grant.
|
|
279
|
+
* The capability SHAPE is core's to define; this site only decides that a pin was asked for.
|
|
280
|
+
*/
|
|
281
|
+
export async function mintControlInstrument(target, tier, instanceId) {
|
|
282
|
+
const identity = newIdentity();
|
|
283
|
+
const uid = mintLifecycleUid();
|
|
284
|
+
const issued = { generation: mintGeneration(), acceptedToken: mintAcceptedToken() };
|
|
285
|
+
const pinned = instanceId !== undefined ? instancePinnedInstrumentCapabilities(tier, instanceId) : undefined;
|
|
286
|
+
const creds = await withIssuerSession({ servers: target.server, space: target.space, auth: target.auth, tls: target.tlsRequired }, (s) => mintCreds(target.auth, identity, tier === "admin" ? "control-caller-admin" : "control-caller-privileged", {
|
|
287
|
+
lifecycleUid: uid,
|
|
288
|
+
...(pinned ? { endpointCapabilities: pinned } : {}),
|
|
289
|
+
issued,
|
|
290
|
+
issuance: { mode: "issue", store: s.store, accepted: s.accepted, sources: [] },
|
|
291
|
+
}));
|
|
292
|
+
return { creds, epCaller: { owner: DEV_OWNER, actor: identity.id, uid, generation: issued.generation } };
|
|
293
|
+
}
|
|
169
294
|
/**
|
|
170
295
|
* Resolve where a mesh-touching command connects + with what creds, THROWING {@link ConnectRefusal}
|
|
171
296
|
* on every refusal instead of ending the process. {@link connectOrExit} is this plus the printing
|
|
@@ -174,7 +299,7 @@ function exitOnRefusal(e) {
|
|
|
174
299
|
* per-user-auth mesh. Those refuse static creds fail-closed because old local creds remain
|
|
175
300
|
* broker-valid but are the wrong identity plane after the flip.
|
|
176
301
|
* • Otherwise → resolve the running mesh from the registry (works from any dir), mint `role` creds
|
|
177
|
-
* on an auth mesh, and preflight with the registry's stale-prune.
|
|
302
|
+
* on an auth mesh, and preflight with the registry's stale-prune unless readOnly is requested.
|
|
178
303
|
*/
|
|
179
304
|
export async function connectOrThrow(flags, role, opts = {}) {
|
|
180
305
|
if (flags.creds) {
|
|
@@ -187,7 +312,7 @@ export async function connectOrThrow(flags, role, opts = {}) {
|
|
|
187
312
|
refuseStaticCredsForKnownUserAuth(space, flags.server, "--creds");
|
|
188
313
|
const server = flags.server ?? DEFAULT_SERVER;
|
|
189
314
|
if (!existsSync(flags.creds))
|
|
190
|
-
throw new ConnectRefusal(`✗ creds file not found: ${flags.creds}
|
|
315
|
+
throw new ConnectRefusal(`✗ creds file not found: ${flags.creds}`, undefined, { code: "USAGE_INVALID" });
|
|
191
316
|
const creds = readFileSync(flags.creds, "utf8");
|
|
192
317
|
// An explicit `--creds` file is an off-registry connect: no mesh record, so no recorded TLS
|
|
193
318
|
// intent to inherit. It stays non-strict, and that is a real (documented) gap rather than a
|
|
@@ -205,13 +330,34 @@ export async function connectOrThrow(flags, role, opts = {}) {
|
|
|
205
330
|
// open broker would credless-connect into a callout denial whose copy sends the operator
|
|
206
331
|
// port-hunting. Name the real state and the recovery instead.
|
|
207
332
|
if (hasUserAuthState(findCotalRoot(), flags.space))
|
|
208
|
-
throw new ConnectRefusal(`✗ space "${flags.space}" has user auth enabled on disk but no usable registry entry - re-record it with \`cotal up\` from its project folder, then sign in (\`cotal login\`)
|
|
333
|
+
throw new ConnectRefusal(`✗ space "${flags.space}" has user auth enabled on disk but no usable registry entry - re-record it with \`cotal up\` from its project folder, then sign in (\`cotal login\`)`, undefined, { code: "TARGET_NOT_FOUND" });
|
|
209
334
|
// A raw OPEN remote broker named entirely on the command line: nothing recorded it, so there
|
|
210
335
|
// is no intent to honour. Non-strict, same documented gap as `--creds`.
|
|
211
336
|
await reachableOrThrow(flags.server, {});
|
|
212
337
|
return { server: flags.server, space: flags.space, tls: false };
|
|
213
338
|
}
|
|
214
|
-
|
|
339
|
+
let target;
|
|
340
|
+
if (opts.readOnly) {
|
|
341
|
+
try {
|
|
342
|
+
target = resolveMeshTarget(process.cwd(), { server: flags.server, space: flags.space, offline: flags.offline, readOnly: true });
|
|
343
|
+
}
|
|
344
|
+
catch (e) {
|
|
345
|
+
if (isWorkspaceTargetError(e))
|
|
346
|
+
throw workspaceRefusal({ kind: "target", error: e }, { cause: e, kind: e.code === "no-meshes" || e.code === "unknown-space" || e.code === "not-started" ? "transient" : "permanent", code: targetErrorCode(e.code) });
|
|
347
|
+
throw e;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else
|
|
351
|
+
target = await resolveTargetOrThrow({ server: flags.server, space: flags.space, offline: flags.offline });
|
|
352
|
+
return connectTargetOrThrow(target, role, opts);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Connect to a mesh the caller already resolved, as {@link connectOrThrow} does once it has
|
|
356
|
+
* resolved one: the logged-in user bearer on a user-auth mesh, a minted `role` credential on a
|
|
357
|
+
* static-auth mesh and none on an open one, then a preflight with the registry's stale-prune unless
|
|
358
|
+
* readOnly is requested. It never resolves a target, so a caller that pinned one connects to it.
|
|
359
|
+
*/
|
|
360
|
+
export async function connectTargetOrThrow(target, role, opts = {}) {
|
|
215
361
|
// USER MODE is a HARD branch: it never mints from on-disk trust material (static creds DO work
|
|
216
362
|
// on a user-auth broker — minting here would silently connect the operator on the wrong identity
|
|
217
363
|
// plane) and never connects credlessly. Everything it needs comes from the login cache + the
|
|
@@ -229,12 +375,12 @@ export async function connectOrThrow(flags, role, opts = {}) {
|
|
|
229
375
|
// subjects can be built. "Never consults role" means never mints by role — not "no triple".
|
|
230
376
|
if (target.mode === "user") {
|
|
231
377
|
if (role === "control-caller-privileged" || role === "control-caller-admin")
|
|
232
|
-
throw new ConnectRefusal(`✗ cannot mint the "${role}" instrument on a user-mode mesh - the logged-in user bearer is the control surface (ledger scope is the grant). Operator instruments are static-mesh only
|
|
378
|
+
throw new ConnectRefusal(`✗ cannot mint the "${role}" instrument on a user-mode mesh - the logged-in user bearer is the control surface (ledger scope is the grant). Operator instruments are static-mesh only.`, undefined, { code: "UNSUPPORTED" });
|
|
233
379
|
// A workflow run's own profiles are minted by the space signer, which a client of a user-auth
|
|
234
380
|
// mesh does not hold; the bearer carries none of their rows. The hosted path refuses too (the
|
|
235
381
|
// manager names why), so the sentence does not steer at it.
|
|
236
382
|
if (role === "run-driver" || role === "run-mediator" || role === "run-operator")
|
|
237
|
-
throw new ConnectRefusal(`✗ cannot mint the "${role}" credential on a user-mode mesh - a run's driver rides a credential only the space signer mints (SPEC 14.6), and a user-auth mesh hosts no runs yet either. Run programs on a static-auth mesh
|
|
383
|
+
throw new ConnectRefusal(`✗ cannot mint the "${role}" credential on a user-mode mesh - a run's driver rides a credential only the space signer mints (SPEC 14.6), and a user-auth mesh hosts no runs yet either. Run programs on a static-auth mesh.`, undefined, { code: "UNSUPPORTED" });
|
|
238
384
|
return userConnectOrThrow(target);
|
|
239
385
|
}
|
|
240
386
|
// An operator INSTRUMENT mint pins a fresh lifecycle uid: its ep-rail caller rows are
|
|
@@ -244,66 +390,44 @@ export async function connectOrThrow(flags, role, opts = {}) {
|
|
|
244
390
|
let creds;
|
|
245
391
|
let epCaller;
|
|
246
392
|
if (target.auth) {
|
|
247
|
-
|
|
248
|
-
|
|
393
|
+
if (role === "deployer") {
|
|
394
|
+
// The deployer is NOT an issuance. It is the one instrument the profile table leaves
|
|
395
|
+
// unbounded (a deploy spans planning, launches and their readiness waits), and an issuance
|
|
396
|
+
// bound to no lifecycle gate must carry an expiry as its liveness (SPEC 13.15), so the mint
|
|
397
|
+
// would refuse it. Nothing it does needs the versioned rail: only `run-start` requires the
|
|
398
|
+
// binding, and a deploy starts no run. It rides the legacy rail under its own uid.
|
|
399
|
+
const identity = newIdentity();
|
|
249
400
|
const uid = mintLifecycleUid();
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const pinned = opts.instanceId !== undefined && role !== "deployer"
|
|
260
|
-
? instancePinnedInstrumentCapabilities(tier, opts.instanceId)
|
|
261
|
-
: undefined;
|
|
262
|
-
if (role === "deployer") {
|
|
263
|
-
// The deployer is NOT an issuance. It is the one instrument the profile table leaves
|
|
264
|
-
// unbounded (a deploy spans planning, launches and their readiness waits), and an issuance
|
|
265
|
-
// bound to no lifecycle gate must carry an expiry as its liveness (SPEC 13.15), so the mint
|
|
266
|
-
// would refuse it. Nothing it does needs the versioned rail: only `run-start` requires the
|
|
267
|
-
// binding, and a deploy starts no run. It rides the legacy rail under its own uid.
|
|
268
|
-
creds = await mintCreds(target.auth, identity, role, { lifecycleUid: uid });
|
|
269
|
-
epCaller = { owner: DEV_OWNER, actor: identity.id, uid };
|
|
401
|
+
creds = await mintCreds(target.auth, identity, role, { lifecycleUid: uid });
|
|
402
|
+
epCaller = { owner: DEV_OWNER, actor: identity.id, uid };
|
|
403
|
+
}
|
|
404
|
+
else if (instrument) {
|
|
405
|
+
// `--on <instanceId>` reaches the mint as `opts.instanceId`. Only the two control-caller
|
|
406
|
+
// tiers take it: `deployer` mints through a different arm that does not consume endpoint
|
|
407
|
+
// capabilities, so pinning it would silently do nothing.
|
|
408
|
+
try {
|
|
409
|
+
({ creds, epCaller } = await mintControlInstrument({ server: target.server, space: target.space, tlsRequired: target.tlsRequired, auth: target.auth }, role === "control-caller-admin" ? "admin" : "privileged", opts.instanceId));
|
|
270
410
|
}
|
|
271
|
-
|
|
272
|
-
//
|
|
273
|
-
//
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
creds = await withIssuerSession({ servers: target.server, space: target.space, auth: target.auth, tls: target.tlsRequired }, (s) => mintCreds(target.auth, identity, role, {
|
|
279
|
-
lifecycleUid: uid,
|
|
280
|
-
...(pinned ? { endpointCapabilities: pinned } : {}),
|
|
281
|
-
issued,
|
|
282
|
-
issuance: { mode: "issue", store: s.store, accepted: s.accepted, sources: [] },
|
|
283
|
-
}));
|
|
284
|
-
}
|
|
285
|
-
catch (e) {
|
|
286
|
-
// The issuer dial is now the first thing on this path to touch the broker. A mesh that
|
|
287
|
-
// is not there must still be reported in the preflight's classified words (and prune the
|
|
288
|
-
// stale entry as before), not as the raw transport error the dial throws. Anything the
|
|
289
|
-
// preflight does not explain is the issuer's own fault and surfaces as such.
|
|
290
|
-
await preflightOrThrow(target);
|
|
291
|
-
throw e;
|
|
292
|
-
}
|
|
293
|
-
epCaller = { owner: DEV_OWNER, actor: identity.id, uid, generation: issued.generation };
|
|
411
|
+
catch (e) {
|
|
412
|
+
// The issuer dial is now the first thing on this path to touch the broker. A mesh that
|
|
413
|
+
// is not there must still be reported in the preflight's classified words (and prune the
|
|
414
|
+
// stale entry as before), not as the raw transport error the dial throws. Anything the
|
|
415
|
+
// preflight does not explain is the issuer's own fault and surfaces as such.
|
|
416
|
+
await preflightOrThrow(target, undefined, opts.readOnly === true);
|
|
417
|
+
throw e;
|
|
294
418
|
}
|
|
295
419
|
}
|
|
296
420
|
else {
|
|
297
|
-
creds = await mintCreds(target.auth,
|
|
421
|
+
creds = await mintCreds(target.auth, newIdentity(), role, opts.mint ?? {});
|
|
298
422
|
}
|
|
299
423
|
}
|
|
300
424
|
// A registered AUTH mesh with no seed is still authenticated. A credless probe would
|
|
301
425
|
// classify it as "open now wants auth" and prune or attach as open. Refuse here,
|
|
302
426
|
// naming the recorded mode.
|
|
303
427
|
if (target.mode === "auth" && !target.auth) {
|
|
304
|
-
throw new ConnectRefusal(`✗ mesh "${target.space}" is a static-auth mesh but the seed under ${target.root} is missing. Restore the seed at that checkout. This mesh is not open
|
|
428
|
+
throw new ConnectRefusal(`✗ mesh "${target.space}" is a static-auth mesh but the seed under ${target.root} is missing. Restore the seed at that checkout. This mesh is not open.`, undefined, { code: "DEPENDENCY_UNAVAILABLE" });
|
|
305
429
|
}
|
|
306
|
-
await preflightOrThrow(target, creds);
|
|
430
|
+
await preflightOrThrow(target, creds, opts.readOnly === true);
|
|
307
431
|
// THE REGISTRY-RESOLVED PATH, and the one that must inherit the recorded decision: if the mesh
|
|
308
432
|
// record says this broker is TLS-required, the connection REQUIRES it. This is the site whose
|
|
309
433
|
// omission had no symptom - it connects either way against an honest broker.
|
|
@@ -345,7 +469,7 @@ export async function connectUserControlOrExit(flags) {
|
|
|
345
469
|
export async function connectUserControlOrThrow(flags) {
|
|
346
470
|
const target = await resolveTargetOrThrow(flags);
|
|
347
471
|
if (target.mode !== "user")
|
|
348
|
-
throw new ConnectRefusal(`✗ connectUserControlOrThrow requires a user-auth mesh (resolved mode is "${target.mode}")
|
|
472
|
+
throw new ConnectRefusal(`✗ connectUserControlOrThrow requires a user-auth mesh (resolved mode is "${target.mode}")`, undefined, { code: "UNSUPPORTED" });
|
|
349
473
|
return userConnectOrThrow(target);
|
|
350
474
|
}
|
|
351
475
|
/** The user-mode connect: resolve the space's auth provider from the registry (composition-root
|
|
@@ -363,7 +487,7 @@ async function userConnectOrThrow(target) {
|
|
|
363
487
|
return await userConnect(target);
|
|
364
488
|
}
|
|
365
489
|
catch (e) {
|
|
366
|
-
throw new ConnectRefusal(`✗ ${e instanceof Error ? e.message : String(e)}`, undefined, { cause: e });
|
|
490
|
+
throw new ConnectRefusal(`✗ ${e instanceof Error ? e.message : String(e)}`, undefined, { cause: e, code: credentialCode(e) });
|
|
367
491
|
}
|
|
368
492
|
}
|
|
369
493
|
async function userConnect(target) {
|
|
@@ -418,7 +542,8 @@ export async function reachableOrThrow(server, auth = {}) {
|
|
|
418
542
|
// of this: it is transport, not identity, and a TLS-only connection presents no credential.
|
|
419
543
|
const hasAuth = Boolean(auth.creds ?? auth.token ?? (auth.user && auth.pass));
|
|
420
544
|
const kind = probe.reason === "timeout" || probe.reason === "unreachable" ? "transient" : "permanent";
|
|
421
|
-
|
|
545
|
+
const code = kind === "transient" ? "TARGET_UNAVAILABLE" : probe.reason === "auth-required" && hasAuth ? "PERMISSION_DENIED" : "AUTH_REQUIRED";
|
|
546
|
+
throw workspaceRefusal({ kind: "reachable", reason: probe.reason, server, hasAuth }, { kind, code });
|
|
422
547
|
}
|
|
423
548
|
/** {@link reachableOrThrow} with the exiting disposition. */
|
|
424
549
|
export async function reachableOrExit(server, auth = {}) {
|
|
@@ -448,26 +573,20 @@ export async function resolveTargetOrThrow(flags) {
|
|
|
448
573
|
// found is transient: the sweep keeps a crashed `up` mesh as offline, so it resolves again once
|
|
449
574
|
// its broker is back. A record that exists and is broken, or several that match, is not.
|
|
450
575
|
if (isWorkspaceTargetError(e)) {
|
|
451
|
-
const kind = e.code === "no-meshes" || e.code === "unknown-space" ? "transient" : "permanent";
|
|
452
|
-
throw
|
|
576
|
+
const kind = e.code === "no-meshes" || e.code === "unknown-space" || e.code === "not-started" ? "transient" : "permanent";
|
|
577
|
+
throw workspaceRefusal({ kind: "target", error: e }, { cause: e, kind, code: targetErrorCode(e.code) });
|
|
453
578
|
}
|
|
454
579
|
throw e;
|
|
455
580
|
}
|
|
456
|
-
// If a dangling `current` was silently bypassed — it named a mesh that's since gone (deleted,
|
|
457
|
-
// or kept as offline) and we fell back to the only live one — say so. The N>1 case errors
|
|
458
|
-
// loudly; this is the one spot that would otherwise quietly redirect a stale default.
|
|
459
|
-
const cur = getCurrent();
|
|
460
|
-
if (cur && (!findMesh(cur) || offline.includes(cur)) && target.source === "registry")
|
|
461
|
-
console.error(c.dim(`note: default mesh "${cur}" is down - using "${target.space}"`));
|
|
462
581
|
return target;
|
|
463
582
|
}
|
|
464
583
|
/** Confirm the resolved mesh is up and accepts these creds — replaces the raw NATS "Authorization
|
|
465
|
-
* Violation" trace with one sentence
|
|
584
|
+
* Violation" trace with one sentence. A readOnly caller never prunes the entry on a mismatch.
|
|
466
585
|
* The probe + classify + render live beside this file; this wrapper owns the operator I/O — it
|
|
467
586
|
* acts on the prune decision, colours, and exits. Probes with `probeCreds` when given (the
|
|
468
587
|
* caller's `--creds`/minted creds); otherwise a throwaway identity is minted from the target's
|
|
469
588
|
* own trust material. */
|
|
470
|
-
export async function preflightOrThrow(target, probeCreds) {
|
|
589
|
+
export async function preflightOrThrow(target, probeCreds, readOnly = false) {
|
|
471
590
|
// USER-mode targets are never credless-probed here: the callout denies a bare connect, the
|
|
472
591
|
// classifier reads that as a stale-entry mismatch, and a mismatch prune would drop a healthy
|
|
473
592
|
// `up` record (found live: foreground `spawn` did exactly this and every later command fell
|
|
@@ -476,7 +595,8 @@ export async function preflightOrThrow(target, probeCreds) {
|
|
|
476
595
|
if (target.mode === "user") {
|
|
477
596
|
if (await isReachable(target.server))
|
|
478
597
|
return;
|
|
479
|
-
|
|
598
|
+
const parts = { message: `no mesh running at ${target.server}; mesh "${target.space}" is recorded at ${target.root} but not running`, remedy: "run `cotal up` there to restart" };
|
|
599
|
+
throw new ConnectRefusal(`✗ ${parts.message} - ${parts.remedy}`, undefined, { kind: "transient", code: "TARGET_UNAVAILABLE", parts });
|
|
480
600
|
}
|
|
481
601
|
const r = await preflightTarget(target, probeCreds);
|
|
482
602
|
if (r.ok)
|
|
@@ -485,9 +605,9 @@ export async function preflightOrThrow(target, probeCreds) {
|
|
|
485
605
|
// record is one an automatic sweep may delete. Liveness (`unreachable`) keeps an `up` record as
|
|
486
606
|
// `offline`; mismatch (creds rejected / mode flipped) still drops it. Manual never deletes.
|
|
487
607
|
// The message reports what ACTUALLY happened, so it never claims a removal that the registry refused.
|
|
488
|
-
const pruned = r.prune ? pruneMesh(target.space, r.kind === "unreachable" ? "gone" : "mismatch") : false;
|
|
608
|
+
const pruned = !readOnly && r.prune ? pruneMesh(target.space, r.kind === "unreachable" ? "gone" : "mismatch") : false;
|
|
489
609
|
const kind = r.kind === "unreachable" || r.kind === "slow-link" ? "transient" : "permanent";
|
|
490
|
-
throw
|
|
610
|
+
throw workspaceRefusal({ kind: "preflight", failure: r.kind, target, pruned }, { kind, code: preflightCode(r.kind) });
|
|
491
611
|
}
|
|
492
612
|
/** {@link preflightOrThrow} with the exiting disposition. */
|
|
493
613
|
export async function preflightOrExit(target, probeCreds) {
|