@cotal-ai/cli 0.6.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/channels.d.ts +4 -2
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +17 -18
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/console.d.ts.map +1 -1
- package/dist/commands/console.js +13 -29
- package/dist/commands/console.js.map +1 -1
- 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 +30 -3
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +6 -13
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.d.ts.map +1 -1
- package/dist/commands/join.js +20 -7
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/meshes.d.ts +5 -0
- package/dist/commands/meshes.d.ts.map +1 -0
- package/dist/commands/meshes.js +25 -0
- package/dist/commands/meshes.js.map +1 -0
- 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 +4 -2
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +84 -25
- 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 +223 -6
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/use.d.ts +7 -0
- package/dist/commands/use.d.ts.map +1 -0
- package/dist/commands/use.js +27 -0
- package/dist/commands/use.js.map +1 -0
- package/dist/commands/web.d.ts.map +1 -1
- package/dist/commands/web.js +60 -28
- package/dist/commands/web.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/connect.d.ts +74 -0
- package/dist/lib/connect.d.ts.map +1 -0
- package/dist/lib/connect.js +91 -0
- package/dist/lib/connect.js.map +1 -0
- 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 +2 -0
- package/dist/lib/meshes.d.ts.map +1 -0
- package/dist/lib/meshes.js +6 -0
- package/dist/lib/meshes.js.map +1 -0
- package/dist/lib/onboard.js +6 -6
- 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/lib/transient.d.ts +7 -6
- package/dist/lib/transient.d.ts.map +1 -1
- package/dist/lib/transient.js +6 -25
- package/dist/lib/transient.js.map +1 -1
- package/dist/web/graph.html +207 -0
- package/dist/web/graph.js +508 -0
- package/dist/web/index.html +6 -0
- package/package.json +6 -2
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply helpers shared by `up -f` / `spawn -f`: turn a {@link PreparedManifest} into the artifacts
|
|
3
|
+
* the launch needs — the channel-registry seed, the resolved launch spec (written for the manager's
|
|
4
|
+
* `supervise --launch`), and the connector-availability preflight. No broker lifecycle here (that's
|
|
5
|
+
* the command), so this stays reusable across both verbs.
|
|
6
|
+
*/
|
|
7
|
+
import { accessSync, constants, renameSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
9
|
+
import { join, delimiter } from "node:path";
|
|
10
|
+
import { ensureDirNoSymlink, registry } from "@cotal-ai/core";
|
|
11
|
+
/** A path-safe run id naming the transient `.cotal/run/<runId>/` dir and tying to the ledger. */
|
|
12
|
+
export function genRunId() {
|
|
13
|
+
return randomBytes(8).toString("hex");
|
|
14
|
+
}
|
|
15
|
+
/** Stable content hash of the resolved launch fields — connector + behavior + ACLs. A change here
|
|
16
|
+
* means a re-declared running agent is stale/restart-required (drift detection). */
|
|
17
|
+
export function hashAgent(a) {
|
|
18
|
+
const stable = JSON.stringify({
|
|
19
|
+
agent: a.agentType,
|
|
20
|
+
model: a.model ?? null,
|
|
21
|
+
role: a.role ?? null,
|
|
22
|
+
body: a.body ?? null,
|
|
23
|
+
capabilities: [...a.capabilities].sort(),
|
|
24
|
+
subscribe: [...a.policy.subscribe].sort(),
|
|
25
|
+
allowSubscribe: [...a.policy.allowSubscribe].sort(),
|
|
26
|
+
allowPublish: [...a.policy.allowPublish].sort(),
|
|
27
|
+
});
|
|
28
|
+
return createHash("sha256").update(stable).digest("hex").slice(0, 16);
|
|
29
|
+
}
|
|
30
|
+
/** Project a prepared agent into the resolved launch-spec form the manager consumes. */
|
|
31
|
+
function toLaunchAgent(a) {
|
|
32
|
+
return {
|
|
33
|
+
name: a.name,
|
|
34
|
+
agent: a.agentType,
|
|
35
|
+
role: a.role,
|
|
36
|
+
model: a.model,
|
|
37
|
+
description: a.description,
|
|
38
|
+
body: a.body,
|
|
39
|
+
capabilities: a.capabilities.length ? a.capabilities : undefined,
|
|
40
|
+
subscribe: a.policy.subscribe,
|
|
41
|
+
allowSubscribe: a.policy.allowSubscribe,
|
|
42
|
+
allowPublish: a.policy.allowPublish,
|
|
43
|
+
personaPath: a.persona,
|
|
44
|
+
hash: hashAgent(a),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Build the launch spec the manager boots from. */
|
|
48
|
+
export function buildLaunchSpec(prepared, runId) {
|
|
49
|
+
return {
|
|
50
|
+
apiVersion: "cotal-launch/v1",
|
|
51
|
+
space: prepared.manifest.space,
|
|
52
|
+
runId,
|
|
53
|
+
agents: prepared.agents.map(toLaunchAgent),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Write the launch spec to `<root>/.cotal/run/<runId>.json` (0600 — it carries persona text +
|
|
57
|
+
* policy) and return its path. A fresh run is exclusive-create (`wx`); a `spawn -f` re-apply reuses
|
|
58
|
+
* the runId, so `update` rewrites it atomically (temp-then-rename, exclusive temp — never follows a
|
|
59
|
+
* pre-planted symlink). Both refuse a symlinked `.cotal`/`run` parent. */
|
|
60
|
+
export function writeLaunchSpec(root, spec, opts = {}) {
|
|
61
|
+
const dir = ensureDirNoSymlink(root, ".cotal", "run");
|
|
62
|
+
const path = join(dir, `${spec.runId}.json`);
|
|
63
|
+
const body = JSON.stringify(spec, null, 2);
|
|
64
|
+
if (opts.update) {
|
|
65
|
+
const tmp = join(dir, `.${spec.runId}.${randomBytes(4).toString("hex")}.tmp`);
|
|
66
|
+
writeFileSync(tmp, body, { mode: 0o600, flag: "wx" });
|
|
67
|
+
renameSync(tmp, path);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
writeFileSync(path, body, { mode: 0o600, flag: "wx" });
|
|
71
|
+
}
|
|
72
|
+
return path;
|
|
73
|
+
}
|
|
74
|
+
/** A channel's registry card (description/instructions/replay…) in the shape `seedChannelRegistry`
|
|
75
|
+
* writes. Oversize description/instructions are rejected at the write path. */
|
|
76
|
+
function cardOf(ch) {
|
|
77
|
+
return {
|
|
78
|
+
...(ch.description !== undefined ? { description: ch.description } : {}),
|
|
79
|
+
...(ch.instructions !== undefined ? { instructions: ch.instructions } : {}),
|
|
80
|
+
...(ch.replay !== undefined ? { replay: ch.replay } : {}),
|
|
81
|
+
...(ch.replayWindow !== undefined ? { replayWindow: ch.replayWindow } : {}),
|
|
82
|
+
...(ch.deliveryClass !== undefined ? { deliveryClass: ch.deliveryClass } : {}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** The channel-registry seed (defaults + every per-channel card) — used by `up -f`, which owns the
|
|
86
|
+
* whole space. */
|
|
87
|
+
export function manifestToChannels(prepared) {
|
|
88
|
+
const channels = {};
|
|
89
|
+
for (const ch of prepared.manifest.channels)
|
|
90
|
+
channels[ch.name] = cardOf(ch);
|
|
91
|
+
return { ...(prepared.manifest.defaults ? { defaults: prepared.manifest.defaults } : {}), channels };
|
|
92
|
+
}
|
|
93
|
+
/** A seed of ONLY the given channels and NO defaults — for `spawn -f`, which seeds the brand-new
|
|
94
|
+
* keys it creates onto a shared mesh and must never rewrite the mesh-wide defaults or a pre-existing
|
|
95
|
+
* (unmanaged) card. */
|
|
96
|
+
export function channelsSeed(channels) {
|
|
97
|
+
const out = {};
|
|
98
|
+
for (const ch of channels)
|
|
99
|
+
out[ch.name] = cardOf(ch);
|
|
100
|
+
return { channels: out };
|
|
101
|
+
}
|
|
102
|
+
/** Preflight the connectors: every distinct connector type must be registered and have its required
|
|
103
|
+
* binaries on PATH — fail before any mutation (no fallback). Returns an error sentence, or "". */
|
|
104
|
+
export function preflightConnectors(prepared) {
|
|
105
|
+
const types = [...new Set(prepared.agents.map((a) => a.agentType))];
|
|
106
|
+
const problems = [];
|
|
107
|
+
for (const type of types) {
|
|
108
|
+
let connector;
|
|
109
|
+
try {
|
|
110
|
+
connector = registry.resolve("connector", type);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
problems.push(`unknown connector "${type}" (no such agent type registered)`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const missing = (connector.requires ?? []).filter((bin) => !binOnPath(bin));
|
|
117
|
+
if (missing.length)
|
|
118
|
+
problems.push(`${type} needs ${missing.join(", ")} on PATH`);
|
|
119
|
+
}
|
|
120
|
+
return problems.join("; ");
|
|
121
|
+
}
|
|
122
|
+
/** Is `bin` an executable on PATH (or an executable absolute/relative path)? POSIX-only — mirrors
|
|
123
|
+
* the manager's own preflight so `up -f` fails the same way `cotal start` would. */
|
|
124
|
+
function binOnPath(bin) {
|
|
125
|
+
const check = (p) => {
|
|
126
|
+
try {
|
|
127
|
+
accessSync(p, constants.X_OK);
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
if (bin.includes("/"))
|
|
135
|
+
return check(bin);
|
|
136
|
+
return (process.env.PATH ?? "").split(delimiter).some((dir) => dir && check(join(dir, bin)));
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/lib/manifest/apply.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,kBAAkB,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AAQ,CAAC,IAAI,CAAC,GAAG,IAAI,UAAU,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED;qFACqF;AACrF,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,KAAK,GAAG,CAAC,CAAS,EAAW,EAAE;QACnC,IAAI,CAAC;YACH,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;IACF,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Located manifest errors. Every validation failure carries the offending file, the YAML path,
|
|
3
|
+
* and (where the node is locatable) a line/column — so the CLI prints `cotal.yaml:12:5: …` instead
|
|
4
|
+
* of a stack trace. All problems found in one pass are collected and thrown together.
|
|
5
|
+
*/
|
|
6
|
+
export interface ManifestIssue {
|
|
7
|
+
message: string;
|
|
8
|
+
/** YAML path to the offending node, e.g. ["channels", "review", "allowPublish"]. */
|
|
9
|
+
path?: (string | number)[];
|
|
10
|
+
line?: number;
|
|
11
|
+
col?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Render one issue as `file:line:col: message (at a.b.c)`. */
|
|
14
|
+
export declare function formatIssue(file: string, i: ManifestIssue): string;
|
|
15
|
+
/** One or more located problems in a manifest. The message lists each on its own line. */
|
|
16
|
+
export declare class ManifestError extends Error {
|
|
17
|
+
readonly file: string;
|
|
18
|
+
readonly issues: ManifestIssue[];
|
|
19
|
+
constructor(file: string, issues: ManifestIssue[]);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/lib/manifest/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,GAAG,MAAM,CAIlE;AAED,0FAA0F;AAC1F,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;gBACrB,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE;CAOlD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Render one issue as `file:line:col: message (at a.b.c)`. */
|
|
2
|
+
export function formatIssue(file, i) {
|
|
3
|
+
const loc = i.line ? `${file}:${i.line}${i.col ? `:${i.col}` : ""}` : file;
|
|
4
|
+
const at = i.path?.length ? ` (at ${i.path.join(".")})` : "";
|
|
5
|
+
return `${loc}: ${i.message}${at}`;
|
|
6
|
+
}
|
|
7
|
+
/** One or more located problems in a manifest. The message lists each on its own line. */
|
|
8
|
+
export class ManifestError extends Error {
|
|
9
|
+
file;
|
|
10
|
+
issues;
|
|
11
|
+
constructor(file, issues) {
|
|
12
|
+
const body = issues.map((i) => ` • ${formatIssue(file, i)}`).join("\n");
|
|
13
|
+
super(`${issues.length} problem(s) in ${file}:\n${body}`);
|
|
14
|
+
this.name = "ManifestError";
|
|
15
|
+
this.file = file;
|
|
16
|
+
this.issues = issues;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/lib/manifest/errors.ts"],"names":[],"mappings":"AAaA,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,CAAgB;IACxD,MAAM,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,OAAO,GAAG,GAAG,KAAK,CAAC,CAAC,OAAO,GAAG,EAAE,EAAE,CAAC;AACrC,CAAC;AAED,0FAA0F;AAC1F,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAS;IACb,MAAM,CAAkB;IACjC,YAAY,IAAY,EAAE,MAAuB;QAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzE,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,kBAAkB,IAAI,MAAM,IAAI,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PreparedManifest } from "./preflight.js";
|
|
2
|
+
export type { ResolvedManifest, ResolvedAgent, ResolvedChannel, AgentPolicy, PersonaPermissions } from "./model.js";
|
|
3
|
+
export type { PreparedManifest } from "./preflight.js";
|
|
4
|
+
export type { PreparedAgent, AgentWarning, InheritedScopes } from "./prepare.js";
|
|
5
|
+
export { resolveManifest } from "./resolve.js";
|
|
6
|
+
export { preparePersonas } from "./preflight.js";
|
|
7
|
+
export { prepareAgent } from "./prepare.js";
|
|
8
|
+
export { renderTopology, renderWarnings, renderInherited } from "./render.js";
|
|
9
|
+
export { ManifestError, formatIssue, type ManifestIssue } from "./errors.js";
|
|
10
|
+
/** Read + fully resolve a manifest file (absolute path recommended). Throws {@link ManifestError}
|
|
11
|
+
* with located problems, or a filesystem error if the file is missing. */
|
|
12
|
+
export declare function loadManifest(path: string): PreparedManifest;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/manifest/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAExE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACpH,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E;2EAC2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAG3D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mesh-manifest library: load a `cotal.yaml` (kind: Mesh) into a launch-ready, validated model.
|
|
3
|
+
* Pipeline: read → {@link resolveManifest} (parse/schema/normalize/invert/semantic) →
|
|
4
|
+
* {@link preparePersonas} (persona reads + merge). Consumed by `topology view`, `up -f`, `spawn -f`.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { resolve } from "node:path";
|
|
8
|
+
import { resolveManifest } from "./resolve.js";
|
|
9
|
+
import { preparePersonas } from "./preflight.js";
|
|
10
|
+
export { resolveManifest } from "./resolve.js";
|
|
11
|
+
export { preparePersonas } from "./preflight.js";
|
|
12
|
+
export { prepareAgent } from "./prepare.js";
|
|
13
|
+
export { renderTopology, renderWarnings, renderInherited } from "./render.js";
|
|
14
|
+
export { ManifestError, formatIssue } from "./errors.js";
|
|
15
|
+
/** Read + fully resolve a manifest file (absolute path recommended). Throws {@link ManifestError}
|
|
16
|
+
* with located problems, or a filesystem error if the file is missing. */
|
|
17
|
+
export function loadManifest(path) {
|
|
18
|
+
const abs = resolve(path);
|
|
19
|
+
return preparePersonas(resolveManifest(readFileSync(abs, "utf8"), abs));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/manifest/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAyB,MAAM,gBAAgB,CAAC;AAKxE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AAE7E;2EAC2E;AAC3E,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,OAAO,eAAe,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const LEDGER_VERSION = "cotal-ledger/v1";
|
|
3
|
+
declare const LedgerAgentSchema: z.ZodObject<{
|
|
4
|
+
requested: z.ZodString;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
id: z.ZodString;
|
|
7
|
+
hash: z.ZodString;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
declare const LedgerSchema: z.ZodObject<{
|
|
10
|
+
apiVersion: z.ZodLiteral<"cotal-ledger/v1">;
|
|
11
|
+
kind: z.ZodLiteral<"MeshLedger">;
|
|
12
|
+
runId: z.ZodString;
|
|
13
|
+
space: z.ZodString;
|
|
14
|
+
server: z.ZodString;
|
|
15
|
+
manifestHash: z.ZodString;
|
|
16
|
+
manifestPath: z.ZodString;
|
|
17
|
+
teardownMode: z.ZodLiteral<"ledger-scoped">;
|
|
18
|
+
created: z.ZodObject<{
|
|
19
|
+
channels: z.ZodArray<z.ZodString>;
|
|
20
|
+
agents: z.ZodArray<z.ZodObject<{
|
|
21
|
+
requested: z.ZodString;
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
hash: z.ZodString;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
export type MeshLedger = z.infer<typeof LedgerSchema>;
|
|
29
|
+
export type LedgerAgent = z.infer<typeof LedgerAgentSchema>;
|
|
30
|
+
/** Assemble a ledger from a `spawn -f` apply result. `agents` carry the manager-reply SPAWNED name
|
|
31
|
+
* (cred-keying) + manifest `requested` key + nkey id + resolved hash; `channels` are the brand-new
|
|
32
|
+
* registry keys this run created. */
|
|
33
|
+
export declare function buildLedger(opts: {
|
|
34
|
+
runId: string;
|
|
35
|
+
space: string;
|
|
36
|
+
server: string;
|
|
37
|
+
manifestHash: string;
|
|
38
|
+
manifestPath: string;
|
|
39
|
+
channels: string[];
|
|
40
|
+
agents: LedgerAgent[];
|
|
41
|
+
}): MeshLedger;
|
|
42
|
+
/** Stable index hash of the manifest source text — ties a `down -f cotal.yaml` back to its ledger
|
|
43
|
+
* (an edited file no longer matches, so `down -f` fails rather than guessing; `--run` is the
|
|
44
|
+
* escape hatch). NOT an integrity check and NOT ownership authority — only a lookup key. */
|
|
45
|
+
export declare function hashManifestSource(src: string): string;
|
|
46
|
+
/** Write the ledger to `<root>/.cotal/manifests/<runId>.json`, `0600`, atomically and refusing a
|
|
47
|
+
* symlinked parent. A brand-new ledger is `wx` (exclusive create); an additive update (re-apply)
|
|
48
|
+
* goes temp-then-rename so `down -f` never reads a half-written file. */
|
|
49
|
+
export declare function writeLedger(root: string, ledger: MeshLedger, opts?: {
|
|
50
|
+
update?: boolean;
|
|
51
|
+
}): string;
|
|
52
|
+
/** Parse + strictly validate a ledger file as **untrusted input** — schema, unknown-key rejection,
|
|
53
|
+
* token-safe run id / agent names, concrete channel keys, and duplicate detection — so the WHOLE
|
|
54
|
+
* ledger is proven before the caller deletes anything (no partial "validated the class I'm about to
|
|
55
|
+
* delete" flow). Throws on any deviation. */
|
|
56
|
+
export declare function loadLedger(path: string): MeshLedger;
|
|
57
|
+
/** Every valid ledger under `<root>/.cotal/manifests/`. Unparseable/foreign files are skipped (a
|
|
58
|
+
* targeted `down -f --run <id>` names one directly); used to resolve a `down -f cotal.yaml` to its
|
|
59
|
+
* run by `manifestHash`. */
|
|
60
|
+
export declare function listLedgers(root: string): Array<{
|
|
61
|
+
path: string;
|
|
62
|
+
ledger: MeshLedger;
|
|
63
|
+
}>;
|
|
64
|
+
/** Resolve a `down -f cotal.yaml` to its ledger by the manifest's content hash. Fails (never
|
|
65
|
+
* guesses) when nothing matches (edited file) or more than one does — `--run <id>` is the escape. */
|
|
66
|
+
export declare function findLedgerByHash(root: string, manifestHash: string): {
|
|
67
|
+
path: string;
|
|
68
|
+
ledger: MeshLedger;
|
|
69
|
+
};
|
|
70
|
+
/** Resolve a ledger by explicit run id (the `--run <id>` path). Validates the id is a safe token
|
|
71
|
+
* before deriving the path. */
|
|
72
|
+
export declare function findLedgerByRun(root: string, runId: string): {
|
|
73
|
+
path: string;
|
|
74
|
+
ledger: MeshLedger;
|
|
75
|
+
};
|
|
76
|
+
/** Derive an owned agent's cred path under the known auth root — `<root>/.cotal/auth/creds/<name>.creds`
|
|
77
|
+
* — from the SPAWNED name, rejecting any name that escapes the creds dir. The ledger never stores a
|
|
78
|
+
* cred path; teardown derives it here and the caller deletes it no-follow ({@link unlinkFileNoFollow}). */
|
|
79
|
+
export declare function ownedCredPath(root: string, spawnedName: string): string;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=ledger.d.ts.map
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CAAE,CAAC,CAwBrF;AAED;sGACsG;AACtG,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAOzG;AAED;gCACgC;AAChC,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAUjG;AAED;;4GAE4G;AAC5G,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAMvE"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `spawn -f` ownership ledger (`cotal-ledger/v1`, one file per run at
|
|
3
|
+
* `.cotal/manifests/<runId>.json`): the durable, creation-only record of exactly what a `spawn -f`
|
|
4
|
+
* deploy added to a shared mesh — the registry keys it created and the agents it spawned (by the
|
|
5
|
+
* manager-reply **spawned** name + nkey id). `down -f` reads it to tear down *only* those resources.
|
|
6
|
+
*
|
|
7
|
+
* Two hard rules, because a tampered ledger could otherwise become arbitrary process/credential/file
|
|
8
|
+
* deletion (the round-8/9 security review):
|
|
9
|
+
* 1. **Store IDs, never arbitrary paths.** Cred paths are *derived* from the known auth root at
|
|
10
|
+
* teardown ({@link ownedCredPath}); the run dir is `.cotal/run/<runId>`. The ledger never names
|
|
11
|
+
* a path to delete.
|
|
12
|
+
* 2. **Treat the file as untrusted on read.** {@link loadLedger} strictly validates the whole
|
|
13
|
+
* ledger (schema, token-safe ids/names, concrete channels, duplicate detection) BEFORE the
|
|
14
|
+
* caller takes any destructive action — fail closed, globally.
|
|
15
|
+
*/
|
|
16
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
17
|
+
import { readFileSync, writeFileSync, readdirSync, renameSync, lstatSync } from "node:fs";
|
|
18
|
+
import { join, resolve, dirname } from "node:path";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
import { assertValidChannel, assertValidName, ensureDirNoSymlink, isConcreteChannel, realDirNoSymlink } from "@cotal-ai/core";
|
|
21
|
+
import { authDir } from "@cotal-ai/workspace";
|
|
22
|
+
export const LEDGER_VERSION = "cotal-ledger/v1";
|
|
23
|
+
// Path-/route-safe token (run id, agent name) and an alphanumeric content hash — same shapes the
|
|
24
|
+
// launch spec uses, so the ledger can't smuggle a traversal/injection string into a derived path.
|
|
25
|
+
const TOKEN = /^[A-Za-z0-9_-]+$/;
|
|
26
|
+
const HASH = /^[A-Za-z0-9]+$/;
|
|
27
|
+
const LedgerAgentSchema = z.strictObject({
|
|
28
|
+
/** The manifest agent key (`agents:` name) — display + the stable key a re-apply matches a declared
|
|
29
|
+
* agent against (the spawned name may collision-number, so it can't be that key). */
|
|
30
|
+
requested: z.string().regex(TOKEN, "requested name must be a path-safe token ([A-Za-z0-9_-])"),
|
|
31
|
+
/** The manager-reply SPAWNED name (collision-numbered, e.g. `socrates-2`) — what creds are filed
|
|
32
|
+
* under; the cred path derives from THIS, never the manifest key. */
|
|
33
|
+
name: z.string().regex(TOKEN, "agent name must be a path-safe token ([A-Za-z0-9_-])"),
|
|
34
|
+
/** The spawned agent's nkey id — the immutable identity `down -f` matches before stopping. */
|
|
35
|
+
id: z.string().min(1),
|
|
36
|
+
/** The resolved hash at spawn (drift/stale detection on re-apply). */
|
|
37
|
+
hash: z.string().regex(HASH, "hash must be alphanumeric"),
|
|
38
|
+
});
|
|
39
|
+
const LedgerSchema = z.strictObject({
|
|
40
|
+
apiVersion: z.literal(LEDGER_VERSION),
|
|
41
|
+
kind: z.literal("MeshLedger"),
|
|
42
|
+
runId: z.string().regex(TOKEN, "runId must be a path-safe token ([A-Za-z0-9_-])"),
|
|
43
|
+
space: z.string().min(1),
|
|
44
|
+
server: z.string().min(1),
|
|
45
|
+
/** Content hash of the source manifest — an INDEX for `down -f cotal.yaml` only, never authority. */
|
|
46
|
+
manifestHash: z.string().regex(HASH, "manifestHash must be alphanumeric"),
|
|
47
|
+
/** The source manifest path — operator/display context only; never derived from or deleted. */
|
|
48
|
+
manifestPath: z.string().min(1),
|
|
49
|
+
teardownMode: z.literal("ledger-scoped"),
|
|
50
|
+
created: z.strictObject({
|
|
51
|
+
/** Registry keys this run CREATED (brand-new only — never adopted/pre-existing). */
|
|
52
|
+
channels: z.array(z.string()),
|
|
53
|
+
agents: z.array(LedgerAgentSchema),
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
/** Assemble a ledger from a `spawn -f` apply result. `agents` carry the manager-reply SPAWNED name
|
|
57
|
+
* (cred-keying) + manifest `requested` key + nkey id + resolved hash; `channels` are the brand-new
|
|
58
|
+
* registry keys this run created. */
|
|
59
|
+
export function buildLedger(opts) {
|
|
60
|
+
return {
|
|
61
|
+
apiVersion: LEDGER_VERSION,
|
|
62
|
+
kind: "MeshLedger",
|
|
63
|
+
runId: opts.runId,
|
|
64
|
+
space: opts.space,
|
|
65
|
+
server: opts.server,
|
|
66
|
+
manifestHash: opts.manifestHash,
|
|
67
|
+
manifestPath: opts.manifestPath,
|
|
68
|
+
teardownMode: "ledger-scoped",
|
|
69
|
+
created: { channels: opts.channels, agents: opts.agents },
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Stable index hash of the manifest source text — ties a `down -f cotal.yaml` back to its ledger
|
|
73
|
+
* (an edited file no longer matches, so `down -f` fails rather than guessing; `--run` is the
|
|
74
|
+
* escape hatch). NOT an integrity check and NOT ownership authority — only a lookup key. */
|
|
75
|
+
export function hashManifestSource(src) {
|
|
76
|
+
return createHash("sha256").update(src).digest("hex").slice(0, 16);
|
|
77
|
+
}
|
|
78
|
+
/** Write the ledger to `<root>/.cotal/manifests/<runId>.json`, `0600`, atomically and refusing a
|
|
79
|
+
* symlinked parent. A brand-new ledger is `wx` (exclusive create); an additive update (re-apply)
|
|
80
|
+
* goes temp-then-rename so `down -f` never reads a half-written file. */
|
|
81
|
+
export function writeLedger(root, ledger, opts = {}) {
|
|
82
|
+
const dir = ensureDirNoSymlink(root, ".cotal", "manifests");
|
|
83
|
+
const path = join(dir, `${ledger.runId}.json`);
|
|
84
|
+
const body = JSON.stringify(ledger, null, 2);
|
|
85
|
+
if (opts.update) {
|
|
86
|
+
// Atomic replace: write a fresh temp (exclusive — never follow a pre-planted symlink), then
|
|
87
|
+
// rename over the target. `rename` replaces the destination name itself, not a symlink target.
|
|
88
|
+
const tmp = join(dir, `.${ledger.runId}.${randomBytes(4).toString("hex")}.tmp`);
|
|
89
|
+
writeFileSync(tmp, body, { mode: 0o600, flag: "wx" });
|
|
90
|
+
renameSync(tmp, path);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
writeFileSync(path, body, { mode: 0o600, flag: "wx" });
|
|
94
|
+
}
|
|
95
|
+
return path;
|
|
96
|
+
}
|
|
97
|
+
/** Parse + strictly validate a ledger file as **untrusted input** — schema, unknown-key rejection,
|
|
98
|
+
* token-safe run id / agent names, concrete channel keys, and duplicate detection — so the WHOLE
|
|
99
|
+
* ledger is proven before the caller deletes anything (no partial "validated the class I'm about to
|
|
100
|
+
* delete" flow). Throws on any deviation. */
|
|
101
|
+
export function loadLedger(path) {
|
|
102
|
+
// No-follow: the ledger drives destructive teardown, so refuse a symlinked ledger file (a symlink
|
|
103
|
+
// could redirect `down -f` to attacker-chosen content). Callers also prove the parent dir chain.
|
|
104
|
+
let st;
|
|
105
|
+
try {
|
|
106
|
+
st = lstatSync(path);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
throw new Error(`ledger ${path}: ${e.message}`);
|
|
110
|
+
}
|
|
111
|
+
if (st.isSymbolicLink())
|
|
112
|
+
throw new Error(`refusing to read ledger "${path}": it is a symlink`);
|
|
113
|
+
if (!st.isFile())
|
|
114
|
+
throw new Error(`refusing to read ledger "${path}": not a regular file`);
|
|
115
|
+
let json;
|
|
116
|
+
try {
|
|
117
|
+
json = JSON.parse(readFileSync(path, "utf8"));
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
throw new Error(`ledger ${path}: ${e.message}`);
|
|
121
|
+
}
|
|
122
|
+
const r = LedgerSchema.safeParse(json);
|
|
123
|
+
if (!r.success)
|
|
124
|
+
throw new Error(`ledger ${path}: ${r.error.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`).join("; ")}`);
|
|
125
|
+
const led = r.data;
|
|
126
|
+
const agents = new Set();
|
|
127
|
+
for (const a of led.created.agents) {
|
|
128
|
+
assertValidName(a.name); // belt-and-suspenders past the regex — it names a derived cred path
|
|
129
|
+
if (agents.has(a.name))
|
|
130
|
+
throw new Error(`ledger ${path}: duplicate owned agent "${a.name}"`);
|
|
131
|
+
agents.add(a.name);
|
|
132
|
+
}
|
|
133
|
+
const channels = new Set();
|
|
134
|
+
for (const ch of led.created.channels) {
|
|
135
|
+
assertValidChannel(ch);
|
|
136
|
+
if (!isConcreteChannel(ch))
|
|
137
|
+
throw new Error(`ledger ${path}: owned channel "${ch}" is not concrete`);
|
|
138
|
+
if (channels.has(ch))
|
|
139
|
+
throw new Error(`ledger ${path}: duplicate owned channel "${ch}"`);
|
|
140
|
+
channels.add(ch);
|
|
141
|
+
}
|
|
142
|
+
return led;
|
|
143
|
+
}
|
|
144
|
+
/** Every valid ledger under `<root>/.cotal/manifests/`. Unparseable/foreign files are skipped (a
|
|
145
|
+
* targeted `down -f --run <id>` names one directly); used to resolve a `down -f cotal.yaml` to its
|
|
146
|
+
* run by `manifestHash`. */
|
|
147
|
+
export function listLedgers(root) {
|
|
148
|
+
// Prove `.cotal/manifests` is a real (non-symlink) directory chain before reading under it — a
|
|
149
|
+
// symlinked parent could redirect `down -f` to attacker-chosen ledgers.
|
|
150
|
+
const dir = realDirNoSymlink(root, ".cotal", "manifests");
|
|
151
|
+
if (!dir)
|
|
152
|
+
return [];
|
|
153
|
+
let names;
|
|
154
|
+
try {
|
|
155
|
+
names = readdirSync(dir);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
const out = [];
|
|
161
|
+
for (const n of names) {
|
|
162
|
+
if (!n.endsWith(".json") || n.startsWith("."))
|
|
163
|
+
continue;
|
|
164
|
+
const p = join(dir, n);
|
|
165
|
+
try {
|
|
166
|
+
const ledger = loadLedger(p);
|
|
167
|
+
if (`${ledger.runId}.json` !== n)
|
|
168
|
+
continue; // filename must match the declared runId (no spoofed authority)
|
|
169
|
+
out.push({ path: p, ledger });
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
/* skip — a foreign/corrupt file isn't this run's ledger; `--run` targets a known one */
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
/** Resolve a `down -f cotal.yaml` to its ledger by the manifest's content hash. Fails (never
|
|
178
|
+
* guesses) when nothing matches (edited file) or more than one does — `--run <id>` is the escape. */
|
|
179
|
+
export function findLedgerByHash(root, manifestHash) {
|
|
180
|
+
const matches = listLedgers(root).filter((l) => l.ledger.manifestHash === manifestHash);
|
|
181
|
+
if (matches.length === 0)
|
|
182
|
+
throw new Error(`no ledger matches this manifest's current contents (was it edited since \`spawn -f\`?) — tear down by run id: \`cotal down -f <file> --run <id>\``);
|
|
183
|
+
if (matches.length > 1)
|
|
184
|
+
throw new Error(`${matches.length} runs share this manifest — name one: ${matches.map((m) => m.ledger.runId).join(", ")} (\`--run <id>\`)`);
|
|
185
|
+
return matches[0];
|
|
186
|
+
}
|
|
187
|
+
/** Resolve a ledger by explicit run id (the `--run <id>` path). Validates the id is a safe token
|
|
188
|
+
* before deriving the path. */
|
|
189
|
+
export function findLedgerByRun(root, runId) {
|
|
190
|
+
assertValidName(runId);
|
|
191
|
+
const dir = realDirNoSymlink(root, ".cotal", "manifests"); // refuse a symlinked manifests parent
|
|
192
|
+
if (!dir)
|
|
193
|
+
throw new Error(`no ledger for run ${runId} (.cotal/manifests is absent)`);
|
|
194
|
+
const path = join(dir, `${runId}.json`);
|
|
195
|
+
const ledger = loadLedger(path); // loadLedger refuses a symlinked ledger file
|
|
196
|
+
// Bind the filename to the contents: a tampered `<runId>.json` whose body declares a DIFFERENT
|
|
197
|
+
// runId must not redirect teardown to that other run's derived run dir / resources.
|
|
198
|
+
if (ledger.runId !== runId)
|
|
199
|
+
throw new Error(`ledger ${path}: declares runId "${ledger.runId}", not "${runId}" — refusing`);
|
|
200
|
+
return { path, ledger };
|
|
201
|
+
}
|
|
202
|
+
/** Derive an owned agent's cred path under the known auth root — `<root>/.cotal/auth/creds/<name>.creds`
|
|
203
|
+
* — from the SPAWNED name, rejecting any name that escapes the creds dir. The ledger never stores a
|
|
204
|
+
* cred path; teardown derives it here and the caller deletes it no-follow ({@link unlinkFileNoFollow}). */
|
|
205
|
+
export function ownedCredPath(root, spawnedName) {
|
|
206
|
+
assertValidName(spawnedName);
|
|
207
|
+
const dir = resolve(authDir(root), "creds");
|
|
208
|
+
const path = resolve(dir, `${spawnedName}.creds`);
|
|
209
|
+
if (dirname(path) !== dir)
|
|
210
|
+
throw new Error(`unsafe owned agent name "${spawnedName}" — cred path escapes ${dir}`);
|
|
211
|
+
return path;
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../../src/lib/manifest/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EA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M,IAAI,KAAK,CAAC,UAAU,IAAI,qBAAqB,MAAM,CAAC,KAAK,WAAW,KAAK,cAAc,CAAC,CAAC;IAC3H,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED;;4GAE4G;AAC5G,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,WAAmB;IAC7D,eAAe,CAAC,WAAW,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,WAAW,QAAQ,CAAC,CAAC;IAClD,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,WAAW,yBAAyB,GAAG,EAAE,CAAC,CAAC;IAClH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live-mesh helpers for `cotal spawn -f` — the network half: a transient, invisible probe endpoint
|
|
3
|
+
* for reading the roster + membership feed, and the admin-tier control calls that drive the running
|
|
4
|
+
* manager's `launch` op. (Channel-registry reads use `readChannelRegistry`, which connects itself.)
|
|
5
|
+
*/
|
|
6
|
+
import { CotalEndpoint, type ControlReply, type Presence } from "@cotal-ai/core";
|
|
7
|
+
export interface MeshConn {
|
|
8
|
+
space: string;
|
|
9
|
+
server: string;
|
|
10
|
+
creds?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Connect a transient, presence-invisible endpoint (it watches the roster but doesn't register
|
|
13
|
+
* itself) used to read live state + drive control. The caller stops it. */
|
|
14
|
+
export declare function connectProbe(conn: MeshConn): Promise<CotalEndpoint>;
|
|
15
|
+
/** Let the presence KV replay settle (roster count steady across two polls, ≤1s), then snapshot the
|
|
16
|
+
* live peers — mirrors the dedup probe in `cotal spawn`. */
|
|
17
|
+
export declare function settleRoster(ep: CotalEndpoint): Promise<Presence[]>;
|
|
18
|
+
/** Poll the manager's control plane until it answers `ps` — it may have just been started detached,
|
|
19
|
+
* so it needs a moment to connect + come up. Returns false on timeout. */
|
|
20
|
+
export declare function waitManagerReady(ep: CotalEndpoint, timeoutMs?: number): Promise<boolean>;
|
|
21
|
+
/** Ask the running manager to launch one resolved agent from the run spec, on the ADMIN tier (the
|
|
22
|
+
* `launch` op is operator-only — a spawn-capable agent must not reach it). The manager derives
|
|
23
|
+
* `.cotal/run/<runId>.json` itself; we pass the runId, never a path. */
|
|
24
|
+
export declare function launchAgent(ep: CotalEndpoint, runId: string, name: string): Promise<ControlReply>;
|
|
25
|
+
//# sourceMappingURL=live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../../../src/lib/manifest/live.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAiB,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEhG,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;4EAC4E;AAC5E,wBAAsB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAczE;AAED;6DAC6D;AAC7D,wBAAsB,YAAY,CAAC,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CASzE;AAED;2EAC2E;AAC3E,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAY9F;AAED;;yEAEyE;AACzE,wBAAsB,WAAW,CAAC,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAEvG"}
|