@cotal-ai/cli 0.103.4 → 0.105.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/README.md +7 -6
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +21 -0
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/app-identity.d.ts +5 -1
- package/dist/commands/app-identity.d.ts.map +1 -1
- package/dist/commands/app-identity.js +2 -2
- package/dist/commands/app-identity.js.map +1 -1
- package/dist/commands/spawn.d.ts +4 -0
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +23 -3
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/team.js +1 -1
- package/dist/commands/team.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +58 -4
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +16 -8
- package/dist/commands/watch.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/app-user-identity.d.ts +8 -1
- package/dist/lib/app-user-identity.d.ts.map +1 -1
- package/dist/lib/app-user-identity.js +15 -4
- package/dist/lib/app-user-identity.js.map +1 -1
- package/dist/lib/delivery-proc.d.ts.map +1 -1
- package/dist/lib/delivery-proc.js +3 -1
- package/dist/lib/delivery-proc.js.map +1 -1
- package/dist/lib/manager-choice.d.ts +17 -0
- package/dist/lib/manager-choice.d.ts.map +1 -1
- package/dist/lib/manager-choice.js +21 -4
- package/dist/lib/manager-choice.js.map +1 -1
- package/dist/lib/manager-proc.d.ts.map +1 -1
- package/dist/lib/manager-proc.js +2 -0
- package/dist/lib/manager-proc.js.map +1 -1
- package/dist/lib/up-report.d.ts +4 -3
- package/dist/lib/up-report.d.ts.map +1 -1
- package/dist/lib/up-report.js +3 -2
- package/dist/lib/up-report.js.map +1 -1
- package/package.json +4 -4
package/dist/commands/up.js
CHANGED
|
@@ -8,7 +8,7 @@ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
|
8
8
|
import { isReachable, dialerFor, DEFAULT_SERVER, DEFAULT_SPACE, createSpaceAuth, serverConfig, openServerConfig, validateTlsMaterial, credsProblem, mintCreds, mintLifecycleUid, DEV_OWNER, mintConnectionEvictorCreds, mintMembershipObserverCreds, newIdentity, setupSpaceStreams, reconcileSpaceTtls, ttlBuckets, standaloneConnectOpts, requireBrokerFloor, parseServerVersion, presenceBucket, MEMBERSHIP_MAX_BYTES, spaceDeletionStreams, isJetStreamMissing, seedChannelRegistry, ensureDefaultDeliveryClass, assertValidChannel, isConcreteChannel, validateChannelConfig, validateChannelDefaults, LEASE_TTL_MS, mkSecretDir, openPrivateAppend, realDirNoSymlink, writeSecretFile, writeSecretFileAtomic, utf16Problem, } from "@cotal-ai/core";
|
|
9
9
|
import { JetStreamApiCodes, jetstreamManager, StorageType } from "@nats-io/jetstream";
|
|
10
10
|
import { Kvm } from "@nats-io/kv";
|
|
11
|
-
import { assertManagerName, readManagerName, readManagerSeatCap, recordManagerName, recordManagerSeatCap, parseSeatCapFlag, seatCapText, assertRecordIdentity, formatRecord, identityRecord, parseRecord, CommandFailure, commandFailureReport, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, terminalWidth, assertSingleSpaceBroker, assertUserAuthInfo, authDir, brokerAddressForDisplay, getSoleSpaceAuth, soleSpaceOf, getSpaceAuth, hasUserAuthState, listSpaceAccounts, preloadSpaceAccounts, putSpaceAuth, brokerAddressKey, canonicalRoot, rootPathProblem, rootControlProblem, clearCurrent, findMesh, findPreparedSpace, homeCotalDir, getCurrent, loadMeshes, preparedSpaceAt, removePreparedSpace, localMeshesForRoot, keepsRegistration, oneLine, presentationOf, writeResult, connectionEvictorCredsKey, membershipConfigPath, membershipObserverCredsKey, membershipRwCredsKey, MEMBERSHIP_CONFIG_KIND, MEMBERSHIP_RW_CREDS_KIND, parsePositiveIntegerFlag, recordMesh, retainedLegacyBroker, meshesForRoot, removeMesh, rotateSystemCreds, setCurrent, staleSystemCreds, SYSTEM_CREDS_FILES, userAuthStateDir, userAuthSpacesOnDisk, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, bindOrdinaryResumeListener, consumeRetiredMaintenance, markOrdinaryResumeActive, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, rootNamesNoSpace, readMaintenanceResumeDocument, seatCheckpointDir, readStoreIdentity, recordOrdinaryResumeManagerCommit, releaseMaintenanceLock, retireOrdinaryResume, settleTokenHandoff, sweepTokenHandoff, writeTokenHandoff, sameStoreIdentity, cutController, readBrokerPolicy, writeBrokerPolicy, removePidPair, writePidPair, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, recordOperationWarning, retainSystemSigningSeed, restoreLeftOut, SPACE_NAME_MAX, spaceNameTooLong, MIN_FILE_STORE, exitCode, } from "@cotal-ai/workspace";
|
|
11
|
+
import { assertManagerName, readManagerName, readManagerSeatCap, recordManagerName, recordManagerSeatCap, parseSeatCapFlag, seatCapText, assertRecordIdentity, formatRecord, identityRecord, parseRecord, CommandFailure, commandFailureReport, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, terminalWidth, assertSingleSpaceBroker, assertUserAuthInfo, authDir, brokerAddressForDisplay, brokerPolicyPath, getSoleSpaceAuth, soleSpaceOf, getSpaceAuth, hasUserAuthState, listSpaceAccounts, preloadSpaceAccounts, putSpaceAuth, brokerAddressKey, canonicalRoot, rootPathProblem, rootControlProblem, clearCurrent, findMesh, findPreparedSpace, homeCotalDir, getCurrent, loadMeshes, preparedSpaceAt, removePreparedSpace, localMeshesForRoot, keepsRegistration, oneLine, presentationOf, writeResult, connectionEvictorCredsKey, membershipConfigPath, membershipObserverCredsKey, membershipRwCredsKey, MEMBERSHIP_CONFIG_KIND, MEMBERSHIP_RW_CREDS_KIND, parsePositiveIntegerFlag, recordMesh, retainedLegacyBroker, meshesForRoot, removeMesh, rotateSystemCreds, setCurrent, staleSystemCreds, SYSTEM_CREDS_FILES, userAuthStateDir, userAuthSpacesOnDisk, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, bindOrdinaryResumeListener, consumeRetiredMaintenance, markOrdinaryResumeActive, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, rootNamesNoSpace, readMaintenanceResumeDocument, seatCheckpointDir, readStoreIdentity, recordOrdinaryResumeManagerCommit, releaseMaintenanceLock, retireOrdinaryResume, settleTokenHandoff, sweepTokenHandoff, writeTokenHandoff, sameStoreIdentity, cutController, readBrokerPolicy, writeBrokerPolicy, removePidPair, writePidPair, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, recordOperationWarning, retainSystemSigningSeed, restoreLeftOut, SPACE_NAME_MAX, spaceNameTooLong, MIN_FILE_STORE, exitCode, } from "@cotal-ai/workspace";
|
|
12
12
|
import { FlagValueRefusal } from "../lib/flag-value-refusal.js";
|
|
13
13
|
import { ensureAuthService, resolveAuthProvider, stopAuthService } from "../lib/auth-proc.js";
|
|
14
14
|
import { resolveSpace } from "../lib/status.js";
|
|
@@ -1319,6 +1319,14 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1319
1319
|
// The manifest route checks its own effective address, which `--server` only overrides.
|
|
1320
1320
|
if (!values.file && values.server !== undefined)
|
|
1321
1321
|
assertTlsIntentServed(values.server, transport, "--server");
|
|
1322
|
+
// AND THE OTHER DIRECTION. `assertTlsIntentServed` refuses a `tls://` address this start would
|
|
1323
|
+
// serve in cleartext; this refuses a `nats://` one it would serve over TLS. `up -f` has carried
|
|
1324
|
+
// the same check since it gained one, and so has a `--server nats://` passed with `--tls-cert`
|
|
1325
|
+
// (see `validateUpArguments`), but a root whose RECORDED policy serves TLS reached neither: it
|
|
1326
|
+
// started a TLS broker, registered it under the `nats://` address nothing can dial, and printed
|
|
1327
|
+
// `TLS: serving <subject> at nats://…` over it.
|
|
1328
|
+
if (!values.file && values.server !== undefined)
|
|
1329
|
+
assertTlsAddressServed(values.server, transport, meshRoot);
|
|
1322
1330
|
// CONTROLLER-OWNED STACK. A root whose stack the service controller owns, or a fresh prepared
|
|
1323
1331
|
// static-auth, open or user-auth root with nothing legacy retained, starts as exact controller members instead
|
|
1324
1332
|
// of the pidfile launcher. The decision is made once here; neither route falls back to the other.
|
|
@@ -1507,14 +1515,26 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1507
1515
|
const keptStopped = registration !== undefined && !resumeAttempt && values.server === undefined && keepsRegistration(registration) && !(await isReachable(registration.server));
|
|
1508
1516
|
const registeredServer = keptStopped ? undefined : registration?.server;
|
|
1509
1517
|
const implicit = !resumeAttempt && registeredServer === undefined && values.server === undefined && values.host === undefined && !values["user-auth"];
|
|
1510
|
-
|
|
1518
|
+
// THE ADDRESS AND THE MODE ARE TWO DECISIONS, and only the address belongs to `--server` and
|
|
1519
|
+
// `--host`. Reading both off `implicit` meant that naming the address dropped the mode: an open
|
|
1520
|
+
// root restarted at the address it already ran on came back in static auth, with a delivery
|
|
1521
|
+
// daemon and no line saying so, and the broker that had served its agents unauthenticated now
|
|
1522
|
+
// refused them. The address still follows the flags; the recorded mode is inherited whenever
|
|
1523
|
+
// this start names no mode of its own.
|
|
1524
|
+
const recorded = resumeAttempt ? undefined : retainedLegacyBroker(cotalRoot());
|
|
1525
|
+
// A flag still wins: `--open` over a root that last ran with auth starts it open, as it always
|
|
1526
|
+
// has, and `--user-auth` asks for the mode the user-auth state decides. Only silence inherits.
|
|
1527
|
+
if (recorded?.open && values["user-auth"] !== true)
|
|
1528
|
+
values.open = true;
|
|
1529
|
+
const retained = implicit ? recorded : undefined;
|
|
1511
1530
|
// An address up chooses for a TLS broker names TLS, as an explicit one must.
|
|
1512
1531
|
const serving = (url) => transport.kind === "tls-required" ? tlsAddress(url) : url;
|
|
1513
1532
|
if (retained) {
|
|
1514
|
-
if (retained.open)
|
|
1515
|
-
values.open = true;
|
|
1516
1533
|
console.log(c.dim(`starting this folder's stopped stack as it last ran: ${serving(retained.server)}${values.open ? ", open" : ""}`));
|
|
1517
1534
|
}
|
|
1535
|
+
else if (recorded?.open) {
|
|
1536
|
+
console.log(c.dim("starting this folder's stopped stack in the mode it last ran: open"));
|
|
1537
|
+
}
|
|
1518
1538
|
else if (implicit) {
|
|
1519
1539
|
const cleaned = cleanedManifestStart(cotalRoot(), recordedSpace, values.open === true);
|
|
1520
1540
|
if (cleaned)
|
|
@@ -1758,6 +1778,11 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1758
1778
|
stderrLine("✗ ", `mesh "${held.space}" is running at ${server} but its presence/lease TTLs could not be reconciled: ${e.message}`, c.red);
|
|
1759
1779
|
process.exit(1);
|
|
1760
1780
|
}
|
|
1781
|
+
// A refresh is a receipt like any other start: it names its mesh before it says anything
|
|
1782
|
+
// about it, and ends with the steps to take. It used to print this one green line alone, so
|
|
1783
|
+
// `up` in a running project's subfolder answered without saying which mesh it reached or what
|
|
1784
|
+
// to do next, while the launch beside it printed both.
|
|
1785
|
+
console.log(`${renderReport({ space: held.space, sections: [] }, "rich", terminalWidth(process.stdout))}\n`);
|
|
1761
1786
|
console.log(c.green(`✓ mesh "${held.space}" already running at ${server}`));
|
|
1762
1787
|
// USER MODE: re-upping IS the documented recovery for a dead auth service (the provider's
|
|
1763
1788
|
// failure copy says "restart it with `cotal up`"), so a refresh must re-ensure the service —
|
|
@@ -1838,6 +1863,9 @@ async function runUp(args, inheritedLock, onAdopt, freshTeamBoot = false, restor
|
|
|
1838
1863
|
// ceiling, the store) from the record as it stands at write time, not from `held`.
|
|
1839
1864
|
recordOurMesh({ space: held.space, server, root, mode: held.mode, ...(userAuth ? { userAuth } : {}), ...(values.host ? { attachHost: values.host } : {}), ...(maxSessions !== undefined ? { maxSessions } : {}), ts: new Date().toISOString() }, "refresh");
|
|
1840
1865
|
seedPersonaAfterUp(root);
|
|
1866
|
+
// The same Next a launch ends with: this mesh runs, so the steps are the ones that use and
|
|
1867
|
+
// stop it. A manager the refresh found or healed is what makes `spawn` one of them.
|
|
1868
|
+
console.log(`\n${renderReport({ sections: [{ title: "Next", blocks: [{ kind: "commands", items: detachedNext({ manager: managerRecordState(undefined, undefined, held.space).state === "alive", machineHome: canonicalRoot(root) === canonicalRoot(homedir()), ...(values.root ? { root } : {}) }, held.space) }] }] }, "rich", terminalWidth(process.stdout))}`);
|
|
1841
1869
|
return;
|
|
1842
1870
|
}
|
|
1843
1871
|
const who = held ? `mesh "${held.space}" (${held.root})` : "a broker not started here";
|
|
@@ -4031,6 +4059,19 @@ export async function claimSpace(space, server, root) {
|
|
|
4031
4059
|
controller = readStackJournal(existing.root)?.journal.space === space;
|
|
4032
4060
|
}
|
|
4033
4061
|
catch { /* named with the legacy stop */ }
|
|
4062
|
+
// THIS project's own space, running at its own address, started again with another one. The
|
|
4063
|
+
// refusal below belongs to a name another folder holds: it reads as if this folder were a
|
|
4064
|
+
// stranger to the space and offers to start a separate one here, when the folder IS that
|
|
4065
|
+
// space's project and a start naming no address joins the mesh already running in it. No
|
|
4066
|
+
// command moves a stack that ran to another address, so say which address it runs at.
|
|
4067
|
+
// The address must differ for this sentence to be true: the early return above compares roots
|
|
4068
|
+
// as written while this compares them resolved, so a record naming this root by another
|
|
4069
|
+
// spelling reaches here at its OWN address, and that case keeps the refusal below.
|
|
4070
|
+
if (canonicalRoot(existing.root) === canonicalRoot(root) && existing.server !== server)
|
|
4071
|
+
throw new CommandFailure("refused", "CONFLICT", `space "${space}" already runs from this project at ${existing.server}, and this start names ${server}; nothing was started`, {
|
|
4072
|
+
target,
|
|
4073
|
+
remedy: `run cotal up here with no --server or --host to reach the mesh at ${existing.server}, or stop it first with cotal down${controller ? " --yes" : ""} in ${shellWord(existing.root)}`,
|
|
4074
|
+
});
|
|
4034
4075
|
throw new CommandFailure("refused", "CONFLICT", `space "${space}" is already in use by a mesh at ${existing.server} (${existing.root})`, { target, remedy: `start a separate space in this folder with cotal up --space <name>, naming one no other folder uses, or stop "${space}" first with cotal down${controller ? " --yes" : ""} in ${shellWord(existing.root)}` });
|
|
4035
4076
|
}
|
|
4036
4077
|
// The recorded root is this root only where it physically resolves, so it is resolved before any
|
|
@@ -4679,6 +4720,19 @@ function assertTlsIntentServed(server, transport, source) {
|
|
|
4679
4720
|
if (tls && transport.kind !== "tls-required")
|
|
4680
4721
|
throw new CommandFailure("refused", "USAGE_INVALID", `${source} names a tls:// address, but no TLS certificate and key are configured, so the broker would serve plaintext; nothing was started`, { target: { server: brokerAddressForDisplay(server) ?? "not displayable" }, remedy: "serve TLS with --tls-cert <cert.pem> --tls-key <key.pem>, or use a nats:// address" });
|
|
4681
4722
|
}
|
|
4723
|
+
/** A broker that serves TLS is dialed `tls://`, so an address naming `nats://` would be recorded,
|
|
4724
|
+
* registered and handed to every later client as plaintext. Refuse it before anything starts,
|
|
4725
|
+
* naming the recorded policy that serves TLS and the address to pass instead. */
|
|
4726
|
+
function assertTlsAddressServed(server, transport, root) {
|
|
4727
|
+
if (transport.kind !== "tls-required")
|
|
4728
|
+
return;
|
|
4729
|
+
if (!server.split(",").some((url) => /^nats:\/\//i.test(url.trim())))
|
|
4730
|
+
return;
|
|
4731
|
+
throw new CommandFailure("refused", "USAGE_INVALID", `this root serves the broker over TLS (${brokerPolicyPath(root)}), so --server must be a tls:// address; nothing was started or written`, {
|
|
4732
|
+
target: { root, server: brokerAddressForDisplay(server) ?? "not displayable" },
|
|
4733
|
+
remedy: `pass --server ${tlsAddress(server)}`,
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4682
4736
|
/** Persist a transport, and the auth callout timeout the broker configuration rendered, after its
|
|
4683
4737
|
* listener starts; a structured boot leaves stdout to its receipt. */
|
|
4684
4738
|
function commitTransportPolicy(root, transport, quietBoot = false, server, authTimeout) {
|