@cotal-ai/cli 0.7.0 → 0.8.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/dist/commands/down-manifest.d.ts +6 -0
- package/dist/commands/down-manifest.d.ts.map +1 -0
- package/dist/commands/down-manifest.js +282 -0
- package/dist/commands/down-manifest.js.map +1 -0
- package/dist/commands/down.d.ts +5 -3
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +24 -4
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/meshes.js +1 -1
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/mint.d.ts.map +1 -1
- package/dist/commands/mint.js +2 -1
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +66 -16
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/spawn-manifest.d.ts +10 -0
- package/dist/commands/spawn-manifest.d.ts.map +1 -0
- package/dist/commands/spawn-manifest.js +197 -0
- package/dist/commands/spawn-manifest.js.map +1 -0
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +31 -4
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/topology.d.ts +10 -0
- package/dist/commands/topology.d.ts.map +1 -0
- package/dist/commands/topology.js +46 -0
- package/dist/commands/topology.js.map +1 -0
- package/dist/commands/up.d.ts +4 -0
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +112 -2
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/use.d.ts +1 -1
- package/dist/commands/use.d.ts.map +1 -1
- package/dist/commands/use.js +1 -1
- package/dist/commands/use.js.map +1 -1
- package/dist/commands/web.d.ts.map +1 -1
- package/dist/commands/web.js +3 -1
- package/dist/commands/web.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/connect.d.ts +18 -16
- package/dist/lib/connect.d.ts.map +1 -1
- package/dist/lib/connect.js +27 -51
- package/dist/lib/connect.js.map +1 -1
- package/dist/lib/delivery-proc.d.ts.map +1 -1
- package/dist/lib/delivery-proc.js +2 -1
- package/dist/lib/delivery-proc.js.map +1 -1
- package/dist/lib/manager-proc.d.ts +4 -0
- package/dist/lib/manager-proc.d.ts.map +1 -1
- package/dist/lib/manager-proc.js +17 -0
- package/dist/lib/manager-proc.js.map +1 -1
- package/dist/lib/manifest/apply.d.ts +29 -0
- package/dist/lib/manifest/apply.d.ts.map +1 -0
- package/dist/lib/manifest/apply.js +138 -0
- package/dist/lib/manifest/apply.js.map +1 -0
- package/dist/lib/manifest/errors.d.ts +21 -0
- package/dist/lib/manifest/errors.d.ts.map +1 -0
- package/dist/lib/manifest/errors.js +19 -0
- package/dist/lib/manifest/errors.js.map +1 -0
- package/dist/lib/manifest/index.d.ts +13 -0
- package/dist/lib/manifest/index.d.ts.map +1 -0
- package/dist/lib/manifest/index.js +21 -0
- package/dist/lib/manifest/index.js.map +1 -0
- package/dist/lib/manifest/ledger.d.ts +81 -0
- package/dist/lib/manifest/ledger.d.ts.map +1 -0
- package/dist/lib/manifest/ledger.js +213 -0
- package/dist/lib/manifest/ledger.js.map +1 -0
- package/dist/lib/manifest/live.d.ts +25 -0
- package/dist/lib/manifest/live.d.ts.map +1 -0
- package/dist/lib/manifest/live.js +61 -0
- package/dist/lib/manifest/live.js.map +1 -0
- package/dist/lib/manifest/model.d.ts +71 -0
- package/dist/lib/manifest/model.d.ts.map +1 -0
- package/dist/lib/manifest/model.js +2 -0
- package/dist/lib/manifest/model.js.map +1 -0
- package/dist/lib/manifest/preflight.d.ts +12 -0
- package/dist/lib/manifest/preflight.d.ts.map +1 -0
- package/dist/lib/manifest/preflight.js +43 -0
- package/dist/lib/manifest/preflight.js.map +1 -0
- package/dist/lib/manifest/prepare.d.ts +57 -0
- package/dist/lib/manifest/prepare.d.ts.map +1 -0
- package/dist/lib/manifest/prepare.js +95 -0
- package/dist/lib/manifest/prepare.js.map +1 -0
- package/dist/lib/manifest/render.d.ts +41 -0
- package/dist/lib/manifest/render.d.ts.map +1 -0
- package/dist/lib/manifest/render.js +177 -0
- package/dist/lib/manifest/render.js.map +1 -0
- package/dist/lib/manifest/resolve.d.ts +5 -0
- package/dist/lib/manifest/resolve.d.ts.map +1 -0
- package/dist/lib/manifest/resolve.js +185 -0
- package/dist/lib/manifest/resolve.js.map +1 -0
- package/dist/lib/manifest/schema.d.ts +103 -0
- package/dist/lib/manifest/schema.d.ts.map +1 -0
- package/dist/lib/manifest/schema.js +77 -0
- package/dist/lib/manifest/schema.js.map +1 -0
- package/dist/lib/manifest/spawn-plan.d.ts +87 -0
- package/dist/lib/manifest/spawn-plan.d.ts.map +1 -0
- package/dist/lib/manifest/spawn-plan.js +75 -0
- package/dist/lib/manifest/spawn-plan.js.map +1 -0
- package/dist/lib/meshes.d.ts +1 -7
- package/dist/lib/meshes.d.ts.map +1 -1
- package/dist/lib/meshes.js +5 -14
- package/dist/lib/meshes.js.map +1 -1
- package/dist/lib/onboard.js +1 -1
- package/dist/lib/onboard.js.map +1 -1
- package/dist/lib/paths.js +1 -1
- package/dist/lib/paths.js.map +1 -1
- package/dist/lib/status.d.ts.map +1 -1
- package/dist/lib/status.js +2 -1
- package/dist/lib/status.js.map +1 -1
- package/dist/web/graph.html +3 -0
- package/dist/web/graph.js +76 -21
- package/package.json +6 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"down-manifest.d.ts","sourceRoot":"","sources":["../../src/commands/down-manifest.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmNxF"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cotal down -f cotal.yaml` — ownership-scoped teardown of a `spawn -f` deploy: stop + remove ONLY
|
|
3
|
+
* the agents/channels that run created, never foreign actors on the shared mesh. The ledger is
|
|
4
|
+
* treated as untrusted input and the WHOLE of it is validated + every path resolved up front, before
|
|
5
|
+
* any destructive action (fail closed). Local-only: works from the same checkout/host that created
|
|
6
|
+
* the run (the ledger is local state).
|
|
7
|
+
*
|
|
8
|
+
* Safety invariants (security/critic/UX early-PR2 review):
|
|
9
|
+
* - find the ledger by manifest hash; an edited file / >1 match FAILS with `--run`, never guesses;
|
|
10
|
+
* - stop an owned agent only when the live agent matches the recorded name AND nkey id — a name
|
|
11
|
+
* match with a different id is left alone (foreign reuse), never stopped by name;
|
|
12
|
+
* - cred paths are DERIVED from the auth root (never read from the ledger) and deleted no-follow;
|
|
13
|
+
* - a ledger-owned channel card is removed only when no members remain and membership is knowable —
|
|
14
|
+
* skipped (best-effort, racy) on ANY uncertainty, including an owned agent that failed to stop;
|
|
15
|
+
* - `--allow-stale` is apply-only and has no effect here.
|
|
16
|
+
*/
|
|
17
|
+
import { lstatSync, readFileSync, rmSync } from "node:fs";
|
|
18
|
+
import { join, resolve } from "node:path";
|
|
19
|
+
import { CONTROL_ADMIN, deleteChannels, isReachable, mintCreds, newIdentity, realDirNoSymlink, subjectMatches, unlinkFileNoFollow, } from "@cotal-ai/core";
|
|
20
|
+
import { authDir, loadSpaceAuth } from "@cotal-ai/workspace";
|
|
21
|
+
import { c } from "../ui.js";
|
|
22
|
+
import { cotalRoot } from "../lib/paths.js";
|
|
23
|
+
import { connectProbe } from "../lib/manifest/live.js";
|
|
24
|
+
import { findLedgerByHash, findLedgerByRun, hashManifestSource, ownedCredPath, writeLedger } from "../lib/manifest/ledger.js";
|
|
25
|
+
export async function downManifest(file, flags) {
|
|
26
|
+
const abs = resolve(file);
|
|
27
|
+
const root = cotalRoot();
|
|
28
|
+
// 1) Resolve the ledger — fail, never guess (edited file / ambiguous → require --run).
|
|
29
|
+
let ledgerPath;
|
|
30
|
+
let ledger;
|
|
31
|
+
try {
|
|
32
|
+
const found = flags.run ? findLedgerByRun(root, flags.run) : findLedgerByHash(root, hashManifestSource(readFileSync(abs, "utf8")));
|
|
33
|
+
ledgerPath = found.path;
|
|
34
|
+
ledger = found.ledger; // loadLedger already validated the WHOLE ledger as untrusted input
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error(c.red(`✗ ${e.message}`));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
// 2) Show exactly what is being torn down BEFORE deleting anything.
|
|
41
|
+
console.log(c.bold(`Tear down run ${ledger.runId}`));
|
|
42
|
+
console.log(c.dim(` ledger: ${ledgerPath}`));
|
|
43
|
+
console.log(c.dim(` manifest: ${ledger.manifestPath} · hash ${ledger.manifestHash}`));
|
|
44
|
+
console.log(c.dim(` mesh: ${ledger.space} @ ${ledger.server}`));
|
|
45
|
+
console.log(c.dim(` owns: ${ledger.created.agents.length} agent(s), ${ledger.created.channels.length} channel(s)`));
|
|
46
|
+
// 3) Resolve every owned path from validated IDs up front — a bad name fails the WHOLE teardown
|
|
47
|
+
// before any side effect (no partial "validated the one I'm deleting" flow).
|
|
48
|
+
let credPaths;
|
|
49
|
+
let runDir;
|
|
50
|
+
let specPath;
|
|
51
|
+
try {
|
|
52
|
+
credPaths = ledger.created.agents.map((a) => ({ requested: a.requested, name: a.name, id: a.id, path: ownedCredPath(root, a.name) }));
|
|
53
|
+
const runParent = realDirNoSymlink(root, ".cotal", "run"); // refuse a symlinked .cotal/run before deriving under it
|
|
54
|
+
runDir = realDirNoSymlink(root, ".cotal", "run", ledger.runId);
|
|
55
|
+
specPath = join(runParent ?? join(root, ".cotal", "run"), `${ledger.runId}.json`);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error(c.red(`✗ refusing teardown — unsafe owned resource: ${e.message}`));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
if (flags.dryRun) {
|
|
62
|
+
console.log(c.bold("\nWould remove (dry run):"));
|
|
63
|
+
for (const a of credPaths)
|
|
64
|
+
console.log(` ${c.red("-")} agent ${a.name} ${c.dim(`(id ${a.id.slice(0, 8)}, creds ${a.path}) — stopped only if name+id match live`)}`);
|
|
65
|
+
for (const ch of ledger.created.channels)
|
|
66
|
+
console.log(` ${c.red("-")} channel ${c.cyan("#" + ch)} ${c.dim("(auth mesh: only if no members remain · open mesh: metadata cleanup, no membership audit)")}`);
|
|
67
|
+
console.log(` ${c.red("-")} run dir ${runDir ?? "(none)"} + ledger ${ledgerPath} ${c.dim("(only if every owned resource is removed/proven gone; else the ledger is kept)")}`);
|
|
68
|
+
console.log(c.dim("\nDry run — nothing was changed. The live membership check + actual disposition happen at apply."));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// 4) Best-effort live teardown: stop owned agents (name AND id match) + remove childless owned
|
|
72
|
+
// channels. If the broker is down, nothing remote is torn down and the ledger is RETAINED.
|
|
73
|
+
const stoppedIds = new Set();
|
|
74
|
+
const removed = [];
|
|
75
|
+
const openNoFeed = []; // owned channels removed on an open mesh with no membership proof
|
|
76
|
+
const skipped = [];
|
|
77
|
+
const creds = await mintIfAuth(root, ledger.space);
|
|
78
|
+
const reachable = await isReachable(ledger.server, creds ? { creds } : undefined);
|
|
79
|
+
let liveById = new Map();
|
|
80
|
+
// controlOk: we completed the live ps/stop/channel pass. A control-plane error (no manager
|
|
81
|
+
// responder, a thrown ps/stop/membership/delete) is teardown UNCERTAINTY, not a crash — we catch
|
|
82
|
+
// it, mark everything unresolved below, and fall through to ledger retention (engineer/security/ux).
|
|
83
|
+
let controlOk = false;
|
|
84
|
+
if (reachable) {
|
|
85
|
+
try {
|
|
86
|
+
const ep = await connectProbe({ space: ledger.space, server: ledger.server, creds });
|
|
87
|
+
try {
|
|
88
|
+
const ps = await ep.requestControl(CONTROL_ADMIN, { op: "ps" });
|
|
89
|
+
// A FAILED ps reply is teardown uncertainty too — not a trustworthy empty roster. Throw so it
|
|
90
|
+
// joins the no-responder/thrown path → controlOk stays false → partial retention (review-ux).
|
|
91
|
+
if (!ps.ok)
|
|
92
|
+
throw new Error(ps.error ?? "ps failed");
|
|
93
|
+
const live = ps.data ?? [];
|
|
94
|
+
liveById = new Map(live.map((r) => [r.id, r]));
|
|
95
|
+
for (const a of ledger.created.agents) {
|
|
96
|
+
const l = liveById.get(a.id);
|
|
97
|
+
if (!l) {
|
|
98
|
+
const sameName = live.find((r) => r.name === a.name);
|
|
99
|
+
if (sameName)
|
|
100
|
+
console.log(c.yellow(` ~ ${a.name}: a different agent (id ${sameName.id.slice(0, 8)}) holds this name — NOT ours, left running`));
|
|
101
|
+
else
|
|
102
|
+
console.log(c.dim(` • ${a.name}: not running`));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const stop = await ep.requestControl(CONTROL_ADMIN, { op: "stop", args: { name: l.name } });
|
|
106
|
+
if (stop.ok) {
|
|
107
|
+
stoppedIds.add(a.id);
|
|
108
|
+
console.log(c.green(` ✓ stopped ${l.name}`));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.log(c.yellow(` ! ${l.name}: stop failed — ${stop.error ?? "unknown"}`));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Channel removal: skip on ANY uncertainty (best-effort, racy — said so in output). The
|
|
115
|
+
// fail-closed "skip when membership is unobservable" rule protects ACL isolation, which exists
|
|
116
|
+
// only on an AUTH mesh; an open mesh has no isolation and no membership feed by design, so an
|
|
117
|
+
// owned card is removable there (otherwise `down -f` could never clean an open dev mesh).
|
|
118
|
+
const openMesh = !creds;
|
|
119
|
+
const stopFailed = ledger.created.agents.some((a) => liveById.has(a.id) && !stoppedIds.has(a.id));
|
|
120
|
+
const snapshot = await ep.readMembership().catch(() => null);
|
|
121
|
+
const ownedIds = new Set(ledger.created.agents.map((a) => a.id));
|
|
122
|
+
const toRemove = [];
|
|
123
|
+
for (const ch of ledger.created.channels) {
|
|
124
|
+
if (stopFailed) {
|
|
125
|
+
skipped.push({ channel: ch, why: "an owned agent failed to stop" });
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (snapshot) {
|
|
129
|
+
const others = snapshot.members.filter((m) => !ownedIds.has(m.id) && (m.durable.includes(ch) || m.live.some((p) => subjectMatches(p, ch))));
|
|
130
|
+
if (others.length) {
|
|
131
|
+
skipped.push({ channel: ch, why: `members present (${others.length})` });
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (!openMesh) {
|
|
136
|
+
skipped.push({ channel: ch, why: "membership unknown (no feed) on an auth mesh" });
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
openNoFeed.push(ch); // open mesh, no feed: removable (no isolation), but no membership proof
|
|
141
|
+
}
|
|
142
|
+
toRemove.push(ch);
|
|
143
|
+
}
|
|
144
|
+
if (toRemove.length) {
|
|
145
|
+
await deleteChannels({ servers: ledger.server, space: ledger.space, creds, channels: toRemove });
|
|
146
|
+
removed.push(...toRemove);
|
|
147
|
+
}
|
|
148
|
+
controlOk = true; // got all the way through — the live pass is trustworthy
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
await ep.stop();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
console.log(c.yellow(` ! ${ledger.server}: control plane unavailable (${e.message}) — nothing torn down remotely; the ledger is RETAINED for a later \`down -f --run ${ledger.runId}\``));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
console.log(c.yellow(` ! ${ledger.server} unreachable — can't stop processes or remove channels; the ledger is RETAINED for a later \`down -f --run ${ledger.runId}\``));
|
|
160
|
+
}
|
|
161
|
+
// 5) Remote resolution: which owned REMOTE resources are NOT proven handled. An agent is unresolved
|
|
162
|
+
// if the broker was unreachable, or it's still live under our recorded id and its stop failed (an
|
|
163
|
+
// id we don't see live is gone; a same-name/different-id agent is foreign, not ours). A channel
|
|
164
|
+
// is unresolved if it wasn't removed.
|
|
165
|
+
// An agent is resolved only when we explicitly stopped it, OR the control pass was trustworthy and
|
|
166
|
+
// its id isn't live (gone). If the broker was unreachable or the control plane failed, only the
|
|
167
|
+
// agents we actually stopped are resolved — everything else is assumed maybe-running (safe).
|
|
168
|
+
const controlReliable = reachable && controlOk;
|
|
169
|
+
const removedSet = new Set(removed);
|
|
170
|
+
const unresolvedAgents = ledger.created.agents.filter((a) => !stoppedIds.has(a.id) && (!controlReliable || liveById.has(a.id)));
|
|
171
|
+
const unresolvedChannels = ledger.created.channels.filter((ch) => !removedSet.has(ch));
|
|
172
|
+
const unresolvedIds = new Set(unresolvedAgents.map((a) => a.id));
|
|
173
|
+
// 6) Local cred cleanup of RESOLVED agents. A cred is deleted only after its own nkey id matches the
|
|
174
|
+
// recorded id. The dispositions, narrowed by review-fact so retention can't strand the ledger:
|
|
175
|
+
// - no file (undefined) → proven absent, resolved;
|
|
176
|
+
// - sub !== id → a foreign/overwritten cred (OUR cred is already gone) — left in place, reported,
|
|
177
|
+
// NOT retained (retaining would re-trigger every retry → a permanently un-downable ledger);
|
|
178
|
+
// - unverifiable (null: symlink/corrupt) → left in place, reported, NOT retained (same trap; a
|
|
179
|
+
// symlink isn't a cred we wrote) — surfaced loudly so a genuine stale cred isn't silent;
|
|
180
|
+
// - id matches but UNLINK THROWS → OUR cred, a recoverable FS error → retained so a retry finishes.
|
|
181
|
+
const unresolvedCredIds = new Set();
|
|
182
|
+
for (const cp of credPaths) {
|
|
183
|
+
if (unresolvedIds.has(cp.id))
|
|
184
|
+
continue; // remote-unresolved agent keeps its cred (still in use / retry)
|
|
185
|
+
const sub = credSubject(cp.path);
|
|
186
|
+
if (sub === undefined)
|
|
187
|
+
continue; // no cred file — proven absent
|
|
188
|
+
if (sub === null) {
|
|
189
|
+
console.error(c.yellow(` ! ${cp.name} creds: unreadable/unverifiable — left in place (resolve by hand if it's a stale cred)`));
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (sub !== cp.id) {
|
|
193
|
+
console.error(c.yellow(` ~ ${cp.name} creds belong to a different agent (id ${sub.slice(0, 8)} ≠ ${cp.id.slice(0, 8)}) — ours is gone, left in place`));
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
if (unlinkFileNoFollow(cp.path))
|
|
198
|
+
console.log(c.dim(` • removed creds for ${cp.name}`));
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
console.error(c.yellow(` ! ${cp.name} creds: ${e.message} — retained for retry`));
|
|
202
|
+
unresolvedCredIds.add(cp.id); // OUR id-verified cred, unlink failed (recoverable) → keep the record
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// 7) Disposition. The ledger is deleted only when EVERY owned resource — remote agents, channels,
|
|
206
|
+
// AND our own credential files — is removed or proven gone; otherwise it's rewritten DOWN to the
|
|
207
|
+
// unresolved set (atomic temp-then-rename) so a later `down -f --run` finishes. Never erase the
|
|
208
|
+
// only ownership record while anything owned may remain (critic/security/engineer/ux PR2 gate).
|
|
209
|
+
const retainIds = new Set([...unresolvedIds, ...unresolvedCredIds]);
|
|
210
|
+
const complete = retainIds.size === 0 && unresolvedChannels.length === 0;
|
|
211
|
+
for (const s of skipped)
|
|
212
|
+
console.log(c.yellow(` ~ left ${c.cyan("#" + s.channel)}: ${s.why}`) + c.dim(" (best-effort membership check — racy)"));
|
|
213
|
+
if (openNoFeed.length)
|
|
214
|
+
console.log(c.dim(` note: removed ${openNoFeed.length} channel(s) on an OPEN mesh with no membership feed — no ACL isolation to protect, no membership proof: ${openNoFeed.map((n) => "#" + n).join(", ")}`));
|
|
215
|
+
if (complete) {
|
|
216
|
+
// Everything owned is removed/proven gone — safe to delete the run dir + launch spec + ledger.
|
|
217
|
+
try {
|
|
218
|
+
unlinkFileNoFollow(specPath);
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
console.error(c.yellow(` ! launch spec: ${e.message}`));
|
|
222
|
+
}
|
|
223
|
+
if (runDir)
|
|
224
|
+
rmSync(runDir, { recursive: true, force: true });
|
|
225
|
+
try {
|
|
226
|
+
unlinkFileNoFollow(ledgerPath);
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
console.error(c.yellow(` ! ledger: ${e.message}`));
|
|
230
|
+
}
|
|
231
|
+
console.log(c.green(`✓ torn down run ${ledger.runId}`) + (removed.length ? c.dim(` — removed ${removed.length} channel(s): ${removed.map((n) => "#" + n).join(", ")}`) : ""));
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
// Partial: rewrite the ledger DOWN to the unresolved resources so a later `down -f --run` finishes.
|
|
235
|
+
const remainAgents = ledger.created.agents.filter((a) => retainIds.has(a.id));
|
|
236
|
+
const remaining = { ...ledger, created: { channels: unresolvedChannels, agents: remainAgents } };
|
|
237
|
+
writeLedger(root, remaining, { update: true });
|
|
238
|
+
console.log(c.yellow(`! partial teardown of run ${ledger.runId}`) +
|
|
239
|
+
c.dim(` — ${remainAgents.length} agent(s) + ${unresolvedChannels.length} channel(s) still owned; ledger kept`));
|
|
240
|
+
if (unresolvedCredIds.size)
|
|
241
|
+
console.log(c.dim(` local credential cleanup incomplete for ${unresolvedCredIds.size} agent(s) — ledger kept for retry`));
|
|
242
|
+
console.log(c.dim(` finish later (broker up / members gone): cotal down -f ${ledger.manifestPath} --run ${ledger.runId}`));
|
|
243
|
+
process.exitCode = 1; // not a full success
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/** Extract the nkey subject (the agent id) from a NATS creds file's user JWT — to verify a cred file
|
|
247
|
+
* belongs to the recorded agent before `down -f` deletes it. Returns `undefined` if the file is
|
|
248
|
+
* absent, or `null` if it can't be verified (symlink / not a regular file / no JWT / unparseable) so
|
|
249
|
+
* the caller fails closed and leaves it. */
|
|
250
|
+
function credSubject(path) {
|
|
251
|
+
let raw;
|
|
252
|
+
try {
|
|
253
|
+
const st = lstatSync(path);
|
|
254
|
+
if (st.isSymbolicLink() || !st.isFile())
|
|
255
|
+
return null;
|
|
256
|
+
raw = readFileSync(path, "utf8");
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
if (e.code === "ENOENT")
|
|
260
|
+
return undefined;
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const jwt = raw.split("\n").find((l) => l && !l.startsWith("-") && l.split(".").length === 3);
|
|
264
|
+
if (!jwt)
|
|
265
|
+
return null;
|
|
266
|
+
try {
|
|
267
|
+
const claims = JSON.parse(Buffer.from(jwt.split(".")[1], "base64url").toString("utf8"));
|
|
268
|
+
return typeof claims.sub === "string" ? claims.sub : null;
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** Mint a manager (admin-control) cred for the ledger's space from the local trust material, or
|
|
275
|
+
* undefined for an open mesh / mismatched checkout (then we connect bare and do local cleanup). */
|
|
276
|
+
async function mintIfAuth(root, space) {
|
|
277
|
+
const auth = loadSpaceAuth(authDir(root));
|
|
278
|
+
if (!auth || auth.space !== space)
|
|
279
|
+
return undefined;
|
|
280
|
+
return mintCreds(auth, newIdentity(), "manager");
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=down-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"down-manifest.js","sourceRoot":"","sources":["../../src/commands/down-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,aAAa,EACb,cAAc,EACd,WAAW,EACX,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACnB,MAAM,gBAA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,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/commands/down.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/** Stop the background processes started by `cotal up --detach` / `cotal setup`:
|
|
2
|
-
*
|
|
3
|
-
|
|
1
|
+
/** Stop the background processes started by `cotal up --detach` / `cotal setup`: the manager, the
|
|
2
|
+
* delivery daemon, the web dashboard, and the mesh. With `-f <cotal.yaml>` (or `--run <id>`) it does
|
|
3
|
+
* an ownership-scoped teardown of a `spawn -f` deploy instead — removing ONLY what that run created
|
|
4
|
+
* (its agents + the channels it added), from the ledger, never the whole shared mesh. */
|
|
5
|
+
export declare function down(argv?: string[]): Promise<void>;
|
|
4
6
|
//# sourceMappingURL=down.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"down.d.ts","sourceRoot":"","sources":["../../src/commands/down.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"down.d.ts","sourceRoot":"","sources":["../../src/commands/down.ts"],"names":[],"mappings":"AAQA;;;0FAG0F;AAC1F,wBAAsB,IAAI,CAAC,IAAI,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAyC7D"}
|
package/dist/commands/down.js
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { clearCurrent, getCurrent, removeMesh } from "@cotal-ai/workspace";
|
|
3
4
|
import { c } from "../ui.js";
|
|
4
5
|
import { cotalPath } from "../lib/paths.js";
|
|
5
6
|
import { resolveSpace } from "../lib/status.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { downManifest } from "./down-manifest.js";
|
|
8
|
+
/** Stop the background processes started by `cotal up --detach` / `cotal setup`: the manager, the
|
|
9
|
+
* delivery daemon, the web dashboard, and the mesh. With `-f <cotal.yaml>` (or `--run <id>`) it does
|
|
10
|
+
* an ownership-scoped teardown of a `spawn -f` deploy instead — removing ONLY what that run created
|
|
11
|
+
* (its agents + the channels it added), from the ledger, never the whole shared mesh. */
|
|
12
|
+
export async function down(argv = []) {
|
|
13
|
+
const { values } = parseArgs({
|
|
14
|
+
args: argv,
|
|
15
|
+
allowPositionals: true,
|
|
16
|
+
options: {
|
|
17
|
+
file: { type: "string", short: "f" }, // ownership-scoped teardown of a spawn -f deploy
|
|
18
|
+
run: { type: "string" }, // tear down by run id (when the manifest was edited since spawn -f)
|
|
19
|
+
"dry-run": { type: "boolean" }, // print what would be removed, change nothing
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
if (values.file || values.run) {
|
|
23
|
+
await downManifest(values.file ?? "<run>", { run: values.run, dryRun: Boolean(values["dry-run"]) });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
9
26
|
const targets = [
|
|
10
27
|
["manager.pid", "manager"],
|
|
11
28
|
["delivery.pid", "delivery daemon"],
|
|
@@ -24,6 +41,9 @@ export async function down() {
|
|
|
24
41
|
// marker. Drop them with the processes so a stale creds file / marker never lingers.
|
|
25
42
|
for (const f of ["delivery.creds", "manager.delivery-aware"])
|
|
26
43
|
rmSync(cotalPath(f), { force: true });
|
|
44
|
+
// Transient `cotal up -f` launch artifacts (launch specs + materialized runtime personas). `up -f`
|
|
45
|
+
// owns the whole mesh, so tearing it down clears all run dirs — they're never authoritative source.
|
|
46
|
+
rmSync(cotalPath("run"), { recursive: true, force: true });
|
|
27
47
|
// Drop this folder's mesh from the registry (and the `current` pointer if it was the default).
|
|
28
48
|
const space = resolveSpace(process.cwd());
|
|
29
49
|
removeMesh(space);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"down.js","sourceRoot":"","sources":["../../src/commands/down.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,C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;IAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACzD,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,KAAK,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,SAAS,GAAG,oBAAoB,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/commands/meshes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCurrent, loadMeshes } from "@cotal-ai/
|
|
1
|
+
import { getCurrent, loadMeshes } from "@cotal-ai/workspace";
|
|
2
2
|
import { c } from "../ui.js";
|
|
3
3
|
import { pruneStaleMeshes } from "../lib/meshes.js";
|
|
4
4
|
/** `cotal meshes` — list the running meshes (one `cotal up` each), with a `*` on the `current`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meshes.js","sourceRoot":"","sources":["../../src/commands/meshes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"meshes.js","sourceRoot":"","sources":["../../src/commands/meshes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,UAAU,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;0EAE0E;AAC1E,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,gBAAgB,EAAE,CAA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","sources":["../../src/commands/mint.ts"],"names":[],"mappings":"AAeA;;;;oGAIoG;AACpG,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAyExD"}
|
package/dist/commands/mint.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync, existsSync } from "node:fs";
|
|
2
2
|
import { resolve, join, dirname } from "node:path";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import {
|
|
4
|
+
import { agentFilePath, loadAgentFile, mintCreds, newIdentity, stripSpaceAuth, } from "@cotal-ai/core";
|
|
5
|
+
import { authDir, loadSpaceAuth } from "@cotal-ai/workspace";
|
|
5
6
|
import { cotalRoot } from "../lib/paths.js";
|
|
6
7
|
import { c } from "../ui.js";
|
|
7
8
|
/** Out-of-band cred minting: generate an identity, sign a profile-scoped user JWT with the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mint.js","sourceRoot":"","sources":["../../src/commands/mint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"mint.js","sourceRoot":"","sources":["../../src/commands/mint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,aAAa,EACb,aAAa,EACb,SAAS,EACT,WAAW,EACX,cAAc,GAEf,MAAM,gBAAgB,C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AAE,IAAI,EAAE,CAAC,CAAC;IAC/F,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC;IACvE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,OAAO,eAAe,IAAI,GAAG,CAAC,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAuCA;;4FAE4F;AAC5F,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzD;AAED;;0EAE0E;AAC1E,wBAAsB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtD;AAwID;;;gGAGgG;AAChG,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BpE"}
|
package/dist/commands/setup.js
CHANGED
|
@@ -4,7 +4,8 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
|
-
import {
|
|
7
|
+
import { DEFAULT_SERVER, isReachable, registry, } from "@cotal-ai/core";
|
|
8
|
+
import { authDir, loadSpaceAuth } from "@cotal-ai/workspace";
|
|
8
9
|
import { brand, brandBold, dim, ok, note, splash } from "../lib/theme.js";
|
|
9
10
|
import { LivePane } from "../lib/live-window.js";
|
|
10
11
|
import { runSteps } from "../lib/steps.js";
|
|
@@ -15,7 +16,7 @@ import { isOnboarded, markOnboarded } from "../lib/onboard.js";
|
|
|
15
16
|
import { machineStatus, meshStatus, onPath, resolveSpace } from "../lib/status.js";
|
|
16
17
|
import { startMeshDetached, up } from "./up.js";
|
|
17
18
|
import { ensureWeb, webUp, WEB_URL } from "./web.js";
|
|
18
|
-
import { cmuxManagerRunning, managerUp, pgrepMatches, stopManager } from "../lib/manager-proc.js";
|
|
19
|
+
import { cmuxManagerRunning, tmuxManagerRunning, managerUp, pgrepMatches, stopManager } from "../lib/manager-proc.js";
|
|
19
20
|
import { ensureControlPlane } from "../lib/delivery-proc.js";
|
|
20
21
|
import { cotalOnPath, displayCmd, isNpx, selfArgv } from "../lib/self-exec.js";
|
|
21
22
|
import { cotalPath, cotalRoot } from "../lib/paths.js";
|
|
@@ -268,24 +269,42 @@ async function offerDemo(haveClaude) {
|
|
|
268
269
|
const isTTY = Boolean(process.stdin.isTTY);
|
|
269
270
|
if (haveClaude && haveAgents && isTTY) {
|
|
270
271
|
const cmux = inCmuxSurface();
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
: "Open the demo? A Claude you drive, with david and sven helping in
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (cmux) {
|
|
272
|
+
const tmux = inTmuxSurface();
|
|
273
|
+
if (cmux) {
|
|
274
|
+
const go = abortIfCancel(await p.confirm({
|
|
275
|
+
message: "Open the cmux demo? A Claude you drive, with david and sven helping in cmux tabs.",
|
|
276
|
+
initialValue: true,
|
|
277
|
+
}));
|
|
278
|
+
if (go) {
|
|
279
279
|
ensureCmuxSession(cotalRoot());
|
|
280
280
|
p.log.success("Session open: drive the 'cotal-main' pane; david and sven are on the mesh in the background.");
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
}
|
|
284
|
+
if (tmux) {
|
|
285
|
+
const go = abortIfCancel(await p.confirm({
|
|
286
|
+
message: "Open the tmux demo? A Claude you drive, with david and sven helping in tmux windows.",
|
|
287
|
+
initialValue: true,
|
|
288
|
+
}));
|
|
289
|
+
if (go) {
|
|
290
|
+
ensureTmuxSession(cotalRoot());
|
|
291
|
+
p.log.success("Session open: switch to the 'cotal-main' window; david and sven are warming up in the background.");
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (!cmux && !tmux) {
|
|
296
|
+
const go = abortIfCancel(await p.confirm({
|
|
297
|
+
message: "Open the demo? A Claude you drive, with david and sven helping in the background.",
|
|
298
|
+
initialValue: true,
|
|
299
|
+
}));
|
|
300
|
+
if (go) {
|
|
301
|
+
// Background pty manager pre-spawns david/sven (managed, despawnable), then we hand this
|
|
302
|
+
// terminal to the driving session. (auth → delivery daemon first, then the manager.)
|
|
303
|
+
await ensureControlPlane({ space: resolveSpace(process.cwd()), server: DEFAULT_SERVER, spawn: [...DEMO_TEAM] });
|
|
304
|
+
p.outro(brand("Launching your session... david and sven are warming up in the background."));
|
|
305
|
+
await spawn(["me", "--prompt", ME_GREETING]);
|
|
306
|
+
process.exit(0);
|
|
307
|
+
}
|
|
289
308
|
}
|
|
290
309
|
}
|
|
291
310
|
else if (isTTY && haveAgents && !haveClaude) {
|
|
@@ -311,6 +330,10 @@ const ME_GREETING = "Greet the operator in a few short lines. Open with one line
|
|
|
311
330
|
function inCmuxSurface() {
|
|
312
331
|
return Boolean(process.env.CMUX_SURFACE_ID);
|
|
313
332
|
}
|
|
333
|
+
/** True when we're running inside a tmux session (tmux sets `$TMUX` to the socket path). */
|
|
334
|
+
function inTmuxSurface() {
|
|
335
|
+
return Boolean(process.env.TMUX);
|
|
336
|
+
}
|
|
314
337
|
/** (Re)open the cmux working session, idempotently. A background cmux-runtime manager pre-spawns
|
|
315
338
|
* david/sven (so they're managed teammates you can `cotal_despawn`) into their own tabs; the
|
|
316
339
|
* focused `cotal-main` workspace is the console + the driving session "me" (your foreground
|
|
@@ -362,6 +385,33 @@ function ensureCmuxSession(cwd) {
|
|
|
362
385
|
}, { focus: true });
|
|
363
386
|
}
|
|
364
387
|
}
|
|
388
|
+
/** (Re)open the tmux working session, idempotently. Mirrors ensureCmuxSession using the "tmux"
|
|
389
|
+
* terminal provider: a background window runs the tmux-runtime manager (pre-spawning david/sven);
|
|
390
|
+
* the focused "cotal-main" window has the console + driving session "me". */
|
|
391
|
+
function ensureTmuxSession(cwd) {
|
|
392
|
+
const term = registry.resolve("terminal", "tmux");
|
|
393
|
+
stopManager();
|
|
394
|
+
const cotal = selfArgv();
|
|
395
|
+
const run = (...args) => ({ command: cotal[0], args: [...cotal.slice(1), ...args], cwd });
|
|
396
|
+
const space = resolveSpace(cwd);
|
|
397
|
+
if (!/^[A-Za-z0-9_.-]+$/.test(space))
|
|
398
|
+
throw new Error(`cotal setup: unsafe space ${JSON.stringify(space)} (allowed: letters, digits, _ . -)`);
|
|
399
|
+
if (!tmuxManagerRunning(space)) {
|
|
400
|
+
for (const label of ["cotal-manager", ...DEMO_TEAM.map((n) => `cotal-${n}`)])
|
|
401
|
+
closeStaleTabs(term, label);
|
|
402
|
+
term.open("cotal-manager", { panes: [run("supervise", "--runtime", "tmux", "--space", space, "--spawn", DEMO_TEAM.join(","))] }, { focus: false });
|
|
403
|
+
}
|
|
404
|
+
if (!pgrepMatches(`spawn me --space ${space}`)) {
|
|
405
|
+
closeStaleTabs(term, "cotal-main");
|
|
406
|
+
term.open("cotal-main", {
|
|
407
|
+
split: { direction: "vertical", ratio: 0.34 },
|
|
408
|
+
panes: [
|
|
409
|
+
run("console", "--space", space),
|
|
410
|
+
{ ...run("spawn", "me", "--space", space, "--prompt", ME_GREETING), confirm: true },
|
|
411
|
+
],
|
|
412
|
+
}, { focus: true });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
365
415
|
/** Close any lingering cmux tabs labelled `name` (dead tabs persist in the tab list after their
|
|
366
416
|
* process exits) so a freshly opened one is the only instance. */
|
|
367
417
|
function closeStaleTabs(term, name) {
|