@cotal-ai/core 0.7.0 → 0.8.1

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 (50) hide show
  1. package/dist/channels.d.ts +11 -0
  2. package/dist/channels.d.ts.map +1 -1
  3. package/dist/channels.js +19 -0
  4. package/dist/channels.js.map +1 -1
  5. package/dist/connector.d.ts +15 -0
  6. package/dist/connector.d.ts.map +1 -1
  7. package/dist/endpoint.d.ts +33 -6
  8. package/dist/endpoint.d.ts.map +1 -1
  9. package/dist/endpoint.js +145 -7
  10. package/dist/endpoint.js.map +1 -1
  11. package/dist/fs-safe.d.ts +28 -0
  12. package/dist/fs-safe.d.ts.map +1 -0
  13. package/dist/fs-safe.js +86 -0
  14. package/dist/fs-safe.js.map +1 -0
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/launch.d.ts +41 -0
  20. package/dist/launch.d.ts.map +1 -0
  21. package/dist/launch.js +10 -0
  22. package/dist/launch.js.map +1 -0
  23. package/dist/lease.d.ts +11 -0
  24. package/dist/lease.d.ts.map +1 -1
  25. package/dist/lease.js.map +1 -1
  26. package/dist/provision.d.ts +0 -11
  27. package/dist/provision.d.ts.map +1 -1
  28. package/dist/provision.js +6 -36
  29. package/dist/provision.js.map +1 -1
  30. package/dist/runtime.d.ts +2 -2
  31. package/dist/runtime.d.ts.map +1 -1
  32. package/dist/streams.d.ts +5 -0
  33. package/dist/streams.d.ts.map +1 -1
  34. package/dist/streams.js +5 -0
  35. package/dist/streams.js.map +1 -1
  36. package/dist/subjects.d.ts +7 -0
  37. package/dist/subjects.d.ts.map +1 -1
  38. package/dist/subjects.js +9 -0
  39. package/dist/subjects.js.map +1 -1
  40. package/dist/terminal.d.ts +10 -3
  41. package/dist/terminal.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/mesh-registry.d.ts +0 -45
  44. package/dist/mesh-registry.d.ts.map +0 -1
  45. package/dist/mesh-registry.js +0 -78
  46. package/dist/mesh-registry.js.map +0 -1
  47. package/dist/mesh-target.d.ts +0 -42
  48. package/dist/mesh-target.d.ts.map +0 -1
  49. package/dist/mesh-target.js +0 -95
  50. package/dist/mesh-target.js.map +0 -1
@@ -1,42 +0,0 @@
1
- import { type SpaceAuth } from "./provision.js";
2
- /**
3
- * One coherent answer to "which mesh does this command act on, and where do its creds + personas
4
- * live" — resolved identically for both, so a spawn can never authenticate to mesh A while loading
5
- * mesh B's persona. Replaces the scattered `loadSpaceAuth(authDir(cotalRoot()))` + `resolveSpace` +
6
- * `DEFAULT_SERVER` guesswork that silently mistook `~/.cotal` for a space.
7
- *
8
- * Pure and offline (no network): `<TAB>` completion uses it as-is; `spawn` adds a reachability
9
- * preflight (`probeConnect`) on top.
10
- */
11
- export interface MeshTarget {
12
- /** Absolute dir whose `.cotal/{auth,agents}` hold trust + personas. */
13
- root: string;
14
- server: string;
15
- space: string;
16
- /** Trust material, or undefined for an open mesh. */
17
- auth?: SpaceAuth;
18
- /** `<root>/.cotal/agents` — the persona catalog for this mesh. */
19
- personaRoot: string;
20
- /** Where the target came from — this also carries OWNERSHIP for pruning. Every value except
21
- * `local-space` and `flag-server` (the two non-registry escape hatches) means the server + mode
22
- * came from a registry record, so a stale-broker failure prunes it. `local-recorded` is a local
23
- * project matched to a registry entry by root: registry-owned for pruning, but quiet on the
24
- * success line (the target is self-evident from cwd, like `local-space`). */
25
- source: "flag-server" | "flag-space" | "local-space" | "local-recorded" | "registry" | "current";
26
- }
27
- export interface ResolveFlags {
28
- /** `--server <url>` — raw broker escape hatch. */
29
- server?: string;
30
- /** `--space <name>` — pick a specific running mesh from the registry. */
31
- space?: string;
32
- }
33
- /**
34
- * Resolve the mesh target by precedence (first match wins):
35
- * 1. `--space` — registry lookup (errors if that space isn't running).
36
- * 2. `--server` — registry entry on that server (for creds/personas), else the local project.
37
- * 3. A genuine local project (`cwd` walks up to a real `.cotal/`) — local wins, like `git config`.
38
- * 4. The registry: 0 ⇒ error; 1 ⇒ use it; N ⇒ `current` if set, else error naming each + its root.
39
- * No silent fallback — an unresolved target throws one human sentence.
40
- */
41
- export declare function resolveMeshTarget(cwd: string, flags?: ResolveFlags): MeshTarget;
42
- //# sourceMappingURL=mesh-target.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mesh-target.d.ts","sourceRoot":"","sources":["../src/mesh-target.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyC,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAUvF;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,kEAAkE;IAClE,WAAW,EAAE,MAAM,CAAC;IACpB;;;;kFAI8E;IAC9E,MAAM,EACF,aAAa,GACb,YAAY,GACZ,aAAa,GACb,gBAAgB,GAChB,UAAU,GACV,SAAS,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA8CD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,YAAiB,GAAG,UAAU,CAgDnF"}
@@ -1,95 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { join, resolve } from "node:path";
3
- import { DEFAULT_SERVER, DEFAULT_SPACE } from "./endpoint.js";
4
- import { authDir, findCotalRoot, loadSpaceAuth } from "./provision.js";
5
- import { findMesh, getCurrent, homeCotalDir, loadMeshes, removeMesh, } from "./mesh-registry.js";
6
- function personaRoot(root) {
7
- return join(root, ".cotal", "agents");
8
- }
9
- function targetFromEntry(m, server, source) {
10
- // Honor the recorded mode: an OPEN mesh connects credlessly even if its root still has auth
11
- // material on disk (e.g. a root that once ran auth mode). Loading it would make `spawn` mint
12
- // creds against a broker that takes none.
13
- let auth;
14
- if (m.mode === "auth") {
15
- auth = loadSpaceAuth(authDir(m.root));
16
- // Defense in depth: the root's on-disk auth must still be for THIS space. A divergence (the root
17
- // was re-`up`ed as a different space without re-recording) would otherwise mint mesh-A creds
18
- // against the entry for space B. Prune the stale entry and fail loud rather than connect wrong.
19
- if (auth && auth.space !== m.space) {
20
- removeMesh(m.space);
21
- throw new Error(`registry entry "${m.space}" points at ${m.root}, whose auth is now for "${auth.space}" — stale entry removed; re-run \`cotal up\` or check \`cotal meshes\``);
22
- }
23
- }
24
- return {
25
- root: m.root,
26
- server,
27
- space: m.space,
28
- auth,
29
- personaRoot: personaRoot(m.root),
30
- source,
31
- };
32
- }
33
- function localTarget(root, server, source) {
34
- const auth = loadSpaceAuth(authDir(root));
35
- return { root, server, space: auth?.space ?? DEFAULT_SPACE, auth, personaRoot: personaRoot(root), source };
36
- }
37
- /** A `.cotal/` that a user actually created here — not the machine-home dir the cwd walk-up lands on
38
- * from outside any project (which has no space, just the daemon's pid/onboard files). */
39
- function isGenuineSpace(root) {
40
- // Normalize both sides — COTAL_HOME may be relative or non-canonical, and a raw string compare
41
- // would then let the real `~/.cotal` masquerade as a project space (or vice-versa).
42
- return resolve(join(root, ".cotal")) !== resolve(homeCotalDir()) && existsSync(join(root, ".cotal"));
43
- }
44
- /**
45
- * Resolve the mesh target by precedence (first match wins):
46
- * 1. `--space` — registry lookup (errors if that space isn't running).
47
- * 2. `--server` — registry entry on that server (for creds/personas), else the local project.
48
- * 3. A genuine local project (`cwd` walks up to a real `.cotal/`) — local wins, like `git config`.
49
- * 4. The registry: 0 ⇒ error; 1 ⇒ use it; N ⇒ `current` if set, else error naming each + its root.
50
- * No silent fallback — an unresolved target throws one human sentence.
51
- */
52
- export function resolveMeshTarget(cwd, flags = {}) {
53
- if (flags.space) {
54
- const m = findMesh(flags.space);
55
- if (!m)
56
- throw new Error(`no mesh named "${flags.space}" is running — see \`cotal meshes\``);
57
- return targetFromEntry(m, flags.server ?? m.server, "flag-space");
58
- }
59
- if (flags.server) {
60
- const m = loadMeshes().find((e) => e.server === flags.server);
61
- if (m)
62
- return targetFromEntry(m, flags.server, "flag-server");
63
- return localTarget(findCotalRoot(cwd), flags.server, "flag-server");
64
- }
65
- const root = findCotalRoot(cwd);
66
- if (isGenuineSpace(root)) {
67
- // Local project wins by root — but if its mesh is in the registry, use the RECORDED server +
68
- // mode, not DEFAULT_SERVER: a project started with `--server …:4333` must spawn against :4333,
69
- // and a recorded OPEN mesh must not mint creds off stale `.cotal/auth` left on disk. Fall back
70
- // to the local default only when nothing is recorded for this root.
71
- const recorded = loadMeshes().find((m) => resolve(m.root) === resolve(root));
72
- if (recorded)
73
- return targetFromEntry(recorded, recorded.server, "local-recorded");
74
- // No record for this root (migration, or our broker went down and the entry was just pruned).
75
- // Before guessing DEFAULT_SERVER, refuse if a DIFFERENT mesh is recorded there — otherwise the
76
- // fallback would silently join someone else's mesh on the default port with our persona (the
77
- // exact silent-wrong-mesh outcome this feature exists to prevent).
78
- const onDefault = loadMeshes().find((m) => m.server === DEFAULT_SERVER && resolve(m.root) !== resolve(root));
79
- if (onDefault)
80
- throw new Error(`another mesh ("${onDefault.space}") is running at ${DEFAULT_SERVER} — run \`cotal up\` here to start yours, or \`--space ${onDefault.space}\` to join it`);
81
- return localTarget(root, DEFAULT_SERVER, "local-space");
82
- }
83
- const meshes = loadMeshes();
84
- if (meshes.length === 0)
85
- throw new Error("no mesh running — run `cotal up` in a project, or pass `--server`");
86
- if (meshes.length === 1)
87
- return targetFromEntry(meshes[0], meshes[0].server, "registry");
88
- const current = getCurrent();
89
- const cur = current ? findMesh(current) : undefined;
90
- if (cur)
91
- return targetFromEntry(cur, cur.server, "current");
92
- const names = meshes.map((m) => `${m.space} (${m.root})`).join(", ");
93
- throw new Error(`multiple meshes running — ${names}. Pick one with \`--space <name>\` or set a default with \`cotal use <name>\`.`);
94
- }
95
- //# sourceMappingURL=mesh-target.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mesh-target.js","sourceRoot":"","sources":["../src/mesh-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AACvF,OAAO,EACL,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,UAAU,GAEX,MAAM,oBAAoB,CAAC;AAyC5B,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,eAAe,CAAC,CAAY,EAAE,MAAc,EAAE,MAA4B;IACjF,4FAA4F;IAC5F,6FAA6F;IAC7F,0CAA0C;IAC1C,IAAI,IAA2B,CAAC;IAChC,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACtB,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC,iGAAiG;QACjG,6FAA6F;QAC7F,gGAAgG;QAChG,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;YACnC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,IAAI,KAAK,CACb,mBAAmB,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,IAAI,4BAA4B,IAAI,CAAC,KAAK,wEAAwE,CAC9J,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO;QACL,IAAI,EAA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