@ipab/cli 0.1.0-rc.12 → 0.1.0-rc.14
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/builtins/skill.ipab.car +0 -0
- package/dist/cli-daemon.d.ts +14 -0
- package/dist/cli-daemon.d.ts.map +1 -0
- package/dist/cli-daemon.js +400 -0
- package/dist/cli-daemon.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1260 -1404
- package/dist/cli.js.map +1 -1
- package/dist/daemon-api.d.ts +80 -0
- package/dist/daemon-api.d.ts.map +1 -0
- package/dist/daemon-api.js +2411 -0
- package/dist/daemon-api.js.map +1 -0
- package/dist/daemon-client.d.ts +322 -0
- package/dist/daemon-client.d.ts.map +1 -0
- package/dist/daemon-client.js +400 -0
- package/dist/daemon-client.js.map +1 -0
- package/dist/daemon-protocol.d.ts +22 -0
- package/dist/daemon-protocol.d.ts.map +1 -0
- package/dist/daemon-protocol.js +39 -0
- package/dist/daemon-protocol.js.map +1 -0
- package/dist/daemon-telemetry.d.ts +86 -0
- package/dist/daemon-telemetry.d.ts.map +1 -0
- package/dist/daemon-telemetry.js +502 -0
- package/dist/daemon-telemetry.js.map +1 -0
- package/dist/daemon-ui.d.ts +68 -0
- package/dist/daemon-ui.d.ts.map +1 -1
- package/dist/daemon-ui.js +283 -4
- package/dist/daemon-ui.js.map +1 -1
- package/dist/daemon.d.ts +10 -0
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +289 -38
- package/dist/daemon.js.map +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +7 -2
- package/dist/identity.js.map +1 -1
- package/dist/ipc.d.ts +19 -7
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +96 -70
- package/dist/ipc.js.map +1 -1
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +18 -3
- package/dist/pins.js.map +1 -1
- package/dist/state-storage.d.ts.map +1 -1
- package/dist/state-storage.js +2 -1
- package/dist/state-storage.js.map +1 -1
- package/dist/state.d.ts +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +3 -2
- package/dist/state.js.map +1 -1
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +7 -2
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm.d.ts +10 -1
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +247 -76
- package/dist/swarm.js.map +1 -1
- package/package.json +4 -4
- package/src/cli-daemon.ts +482 -0
- package/src/cli.ts +1689 -1948
- package/src/daemon-api.ts +3148 -0
- package/src/daemon-client.ts +975 -0
- package/src/daemon-protocol.ts +61 -0
- package/src/daemon-telemetry.ts +656 -0
- package/src/daemon-ui.ts +361 -4
- package/src/daemon.ts +337 -43
- package/src/identity.ts +10 -2
- package/src/ipc.ts +113 -79
- package/src/pins.ts +23 -3
- package/src/state-storage.ts +5 -1
- package/src/state.ts +3 -1
- package/src/swarm-files.ts +10 -2
- package/src/swarm.ts +727 -497
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import { lstat, readFile } from "node:fs/promises";
|
|
3
|
-
import {
|
|
4
|
-
import { CID } from "multiformats/cid";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
5
|
import stringWidth from "string-width";
|
|
6
6
|
import { LOCAL_SWARM_ALIAS, configKey, effectiveConfig, isLocalSwarm, parseValue, publicUrl, stateLocation, storeConfiguration, swarmUrl, visibleConfig, } from "./config.js";
|
|
7
7
|
import { HostError, object, syntax } from "./host-error.js";
|
|
8
|
-
import {
|
|
8
|
+
import { exactCid, swarmAlias, State, } from "./state.js";
|
|
9
9
|
import { formatNameReference, parseNameReference, formalName, templateName, } from "./name-reference.js";
|
|
10
10
|
import { normalizeSwarmFsPath } from "./swarm-fs-path.js";
|
|
11
11
|
import { readSecretStream } from "./config-secret.js";
|
|
12
|
+
import { openCliClient, resolveLocalPathIfPresent, resolveSwarmFromList, runPreparedApp, } from "./cli-daemon.js";
|
|
12
13
|
let progressLine = false;
|
|
13
14
|
export const processIO = {
|
|
14
15
|
out(text) {
|
|
@@ -150,7 +151,7 @@ const commandHelp = {
|
|
|
150
151
|
"ipab --json daemon ui",
|
|
151
152
|
],
|
|
152
153
|
notes: [
|
|
153
|
-
"
|
|
154
|
+
"Ensures the local daemon is running for the selected state-dir, then shows or opens its protected loopback status WebUI.",
|
|
154
155
|
"The WebUI binds strictly to 127.0.0.1, validates Host/Origin headers against DNS rebinding, and never exposes private keys, swarm.key or Kubo Bearer tokens.",
|
|
155
156
|
],
|
|
156
157
|
},
|
|
@@ -1734,10 +1735,8 @@ export function parse(argv) {
|
|
|
1734
1735
|
return result;
|
|
1735
1736
|
}
|
|
1736
1737
|
async function performCli(argv, io, env) {
|
|
1737
|
-
let
|
|
1738
|
-
let
|
|
1739
|
-
let appExitCode;
|
|
1740
|
-
let readContext;
|
|
1738
|
+
let cliHandle;
|
|
1739
|
+
let daemonStore;
|
|
1741
1740
|
try {
|
|
1742
1741
|
const parsed = parse(argv);
|
|
1743
1742
|
if (parsed.help) {
|
|
@@ -1753,6 +1752,8 @@ async function performCli(argv, io, env) {
|
|
|
1753
1752
|
}
|
|
1754
1753
|
if (parsed.path === "history remove" && !parsed.options.yes && !io.tty)
|
|
1755
1754
|
syntax("Non-interactive history remove requires --yes.");
|
|
1755
|
+
const stateDir = stateLocation(parsed.flags, env).path;
|
|
1756
|
+
// Exempt command #3: doctor (never auto-starts Daemon)
|
|
1756
1757
|
if (parsed.path === "doctor") {
|
|
1757
1758
|
const { doctorDevice, doctorText } = await import("./doctor.js");
|
|
1758
1759
|
const controller = new AbortController();
|
|
@@ -1765,7 +1766,7 @@ async function performCli(argv, io, env) {
|
|
|
1765
1766
|
process.once("SIGINT", interrupt);
|
|
1766
1767
|
process.once("SIGTERM", terminate);
|
|
1767
1768
|
try {
|
|
1768
|
-
const result = await doctorDevice(
|
|
1769
|
+
const result = await doctorDevice(stateDir, env, {
|
|
1769
1770
|
diagnostic: (text, progress) => {
|
|
1770
1771
|
io.err(text, progress);
|
|
1771
1772
|
},
|
|
@@ -1783,116 +1784,317 @@ async function performCli(argv, io, env) {
|
|
|
1783
1784
|
process.removeListener("SIGTERM", terminate);
|
|
1784
1785
|
}
|
|
1785
1786
|
}
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1787
|
+
// Exempt command #4: daemon (foreground daemon host itself)
|
|
1788
|
+
if (parsed.path === "daemon") {
|
|
1789
|
+
if (parsed.flags.json)
|
|
1790
|
+
syntax("--json is not supported for daemon; diagnostics are written to stderr.");
|
|
1791
|
+
const [{ IpfsStore }, { builtinContent }, { serveDaemon }, { swarmDaemon }, { syncDaemonSwarm },] = await Promise.all([
|
|
1792
|
+
import("@ipab/ipfs-store"),
|
|
1793
|
+
import("./builtins.js"),
|
|
1794
|
+
import("./daemon.js"),
|
|
1795
|
+
import("./swarm.js"),
|
|
1796
|
+
import("./skills.js"),
|
|
1797
|
+
]);
|
|
1798
|
+
const builtins = await builtinContent();
|
|
1799
|
+
const bootState = new State(stateDir, builtins.pins, env);
|
|
1800
|
+
let items;
|
|
1801
|
+
try {
|
|
1802
|
+
items = effectiveConfig(bootState.config({ includeSecrets: true }), parsed.flags, env, (reference) => bootState.resolveSwarm(reference));
|
|
1803
|
+
}
|
|
1804
|
+
finally {
|
|
1805
|
+
bootState.close();
|
|
1806
|
+
}
|
|
1807
|
+
const val = (key) => items.find((item) => item.key === key).value;
|
|
1808
|
+
daemonStore = new IpfsStore(await storeConfiguration(val("store.gateway")));
|
|
1809
|
+
const context = {
|
|
1810
|
+
get store() {
|
|
1811
|
+
return daemonStore;
|
|
1812
|
+
},
|
|
1813
|
+
set store(next) {
|
|
1814
|
+
daemonStore = next;
|
|
1815
|
+
},
|
|
1816
|
+
env,
|
|
1817
|
+
stateDir,
|
|
1818
|
+
cacheTtl: Number(val("swarm.cacheTtl")),
|
|
1819
|
+
syncInterval: Number(val("swarm.syncInterval")),
|
|
1820
|
+
listen: val("swarm.listen") === "loopback" ? "loopback" : "lan",
|
|
1821
|
+
...(items.find((item) => item.key === "swarm.pivot").source ===
|
|
1822
|
+
"default"
|
|
1823
|
+
? {}
|
|
1824
|
+
: { pivot: Boolean(val("swarm.pivot")) }),
|
|
1825
|
+
daemonReady: (status, onListen, extra) => serveDaemon(stateDir, {
|
|
1826
|
+
port: Number(val("daemon.uiPort")),
|
|
1827
|
+
env,
|
|
1828
|
+
...(status ? { status } : {}),
|
|
1829
|
+
...(onListen ? { onListen } : {}),
|
|
1830
|
+
...(extra ?? {}),
|
|
1831
|
+
}),
|
|
1832
|
+
forceRefresh: Boolean(val("swarm.forceRefresh")),
|
|
1833
|
+
diagnostic: (text) => {
|
|
1834
|
+
io.err(text);
|
|
1835
|
+
},
|
|
1836
|
+
...(typeof val("pointers.service") === "string"
|
|
1837
|
+
? { pointerService: String(val("pointers.service")) }
|
|
1838
|
+
: {}),
|
|
1839
|
+
...(typeof val("pointers.apiKey") === "string"
|
|
1840
|
+
? { pointerApiKey: String(val("pointers.apiKey")) }
|
|
1841
|
+
: {}),
|
|
1842
|
+
};
|
|
1843
|
+
const controller = new AbortController();
|
|
1844
|
+
const interrupt = () => {
|
|
1845
|
+
controller.abort();
|
|
1846
|
+
};
|
|
1847
|
+
process.once("SIGINT", interrupt);
|
|
1848
|
+
process.once("SIGTERM", interrupt);
|
|
1849
|
+
try {
|
|
1850
|
+
await swarmDaemon(context, controller.signal, (ctx, url, report) => syncDaemonSwarm(ctx, url, undefined, report));
|
|
1851
|
+
}
|
|
1852
|
+
catch (cause) {
|
|
1853
|
+
if (!controller.signal.aborted)
|
|
1854
|
+
throw cause;
|
|
1855
|
+
}
|
|
1856
|
+
finally {
|
|
1857
|
+
process.removeListener("SIGINT", interrupt);
|
|
1858
|
+
process.removeListener("SIGTERM", interrupt);
|
|
1859
|
+
}
|
|
1800
1860
|
return 0;
|
|
1801
1861
|
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
: await (await import("./builtins.js")).builtinContent();
|
|
1805
|
-
state = new State(stateLocation(parsed.flags, env).path, builtins.pins, env);
|
|
1862
|
+
// Exempt recovery: config reset store.rpc runs directly on local State so
|
|
1863
|
+
// legacy store.rpc recovery is never blocked by Daemon startup calling state.config().
|
|
1806
1864
|
if (parsed.path === "config reset" &&
|
|
1807
1865
|
parsed.positional[0] === "store.rpc") {
|
|
1808
|
-
|
|
1866
|
+
const localState = new State(stateDir, [], env);
|
|
1867
|
+
try {
|
|
1868
|
+
localState.resetConfig("store.rpc");
|
|
1869
|
+
}
|
|
1870
|
+
finally {
|
|
1871
|
+
localState.close();
|
|
1872
|
+
}
|
|
1809
1873
|
io.out(parsed.flags.json
|
|
1810
1874
|
? JSON.stringify({ reset: ["store.rpc"] })
|
|
1811
1875
|
: "Removed legacy store.rpc configuration. Existing Kubo pins and content are unchanged.");
|
|
1812
1876
|
return 0;
|
|
1813
1877
|
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
"
|
|
1819
|
-
"
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1878
|
+
// Stateless local build when --no-import is set (never touches IpfsStore or spawns a Daemon).
|
|
1879
|
+
if ((parsed.path === "build" || parsed.path === "bundle build") &&
|
|
1880
|
+
Boolean(parsed.options["no-import"])) {
|
|
1881
|
+
const [{ assembleBundle }, { buildBundle }, { message }] = await Promise.all([
|
|
1882
|
+
import("./assembly.js"),
|
|
1883
|
+
import("./authoring.js"),
|
|
1884
|
+
import("./errors.js"),
|
|
1885
|
+
]);
|
|
1886
|
+
let savedConfig = {};
|
|
1887
|
+
if (existsSync(join(stateDir, "state.sqlite"))) {
|
|
1888
|
+
const localState = new State(stateDir, [], env);
|
|
1889
|
+
try {
|
|
1890
|
+
savedConfig = localState.config({ includeSecrets: false });
|
|
1891
|
+
}
|
|
1892
|
+
finally {
|
|
1893
|
+
localState.close();
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
const outputDirOpt = String(effectiveConfig(savedConfig, parsed.flags, env).find((item) => item.key === "bundle.outputDir").value);
|
|
1897
|
+
const outputOpt = typeof parsed.options.output === "string"
|
|
1898
|
+
? resolve(parsed.options.output)
|
|
1899
|
+
: undefined;
|
|
1900
|
+
const controller = new AbortController();
|
|
1901
|
+
let cancelled = 0;
|
|
1902
|
+
const interrupt = () => {
|
|
1903
|
+
cancelled = 130;
|
|
1904
|
+
controller.abort(new Error("Interrupted."));
|
|
1905
|
+
};
|
|
1906
|
+
const terminate = () => {
|
|
1907
|
+
cancelled = 143;
|
|
1908
|
+
controller.abort(new Error("Terminated."));
|
|
1909
|
+
};
|
|
1910
|
+
process.once("SIGINT", interrupt);
|
|
1911
|
+
process.once("SIGTERM", terminate);
|
|
1912
|
+
try {
|
|
1913
|
+
const commonOpts = {
|
|
1914
|
+
signal: controller.signal,
|
|
1915
|
+
diagnostic: (text) => {
|
|
1916
|
+
io.err(text);
|
|
1917
|
+
},
|
|
1918
|
+
replace: Boolean(parsed.options.replace),
|
|
1919
|
+
...(outputOpt !== undefined ? { output: outputOpt } : {}),
|
|
1920
|
+
outputDir: outputDirOpt,
|
|
1921
|
+
};
|
|
1922
|
+
let built;
|
|
1923
|
+
if (parsed.path === "build") {
|
|
1924
|
+
const sourcePath = parsed.positional[0]
|
|
1925
|
+
? resolve(parsed.positional[0])
|
|
1926
|
+
: process.cwd();
|
|
1927
|
+
io.err("Assembling and validating Bundle (no compilation)...");
|
|
1928
|
+
built = await assembleBundle(sourcePath, commonOpts);
|
|
1929
|
+
}
|
|
1930
|
+
else {
|
|
1931
|
+
const sourcePath = await resolveLocalPathIfPresent(parsed.positional[0]);
|
|
1932
|
+
io.err("Validating and building bundle...");
|
|
1933
|
+
built = await buildBundle(sourcePath, {
|
|
1934
|
+
...commonOpts,
|
|
1935
|
+
schemaOnly: Boolean(parsed.options["schema-only"]),
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
controller.signal.throwIfAborted();
|
|
1939
|
+
const result = { ...built, imported: false };
|
|
1940
|
+
const validation = result.validation;
|
|
1941
|
+
const human = `CID: ${result.cid}\nSchema CID: ${result.schemaCid}\nCAR: ${result.output}${validation !== undefined ? `\nEntry validation: ${validation?.status ?? "not-applicable"}` : ""}\nStore: not imported (--no-import)`;
|
|
1942
|
+
io.out(parsed.flags.json ? JSON.stringify(result) : human);
|
|
1943
|
+
return 0;
|
|
1944
|
+
}
|
|
1945
|
+
catch (cause) {
|
|
1946
|
+
if (cancelled) {
|
|
1947
|
+
io.err(message(cause));
|
|
1948
|
+
return cancelled;
|
|
1949
|
+
}
|
|
1950
|
+
throw cause;
|
|
1951
|
+
}
|
|
1952
|
+
finally {
|
|
1953
|
+
process.removeListener("SIGINT", interrupt);
|
|
1954
|
+
process.removeListener("SIGTERM", terminate);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
// Stateless local CAR inspection (never touches state.sqlite, IpfsStore, or spawns a Daemon).
|
|
1958
|
+
if (parsed.path === "bundle inspect") {
|
|
1959
|
+
const target = parsed.positional[0];
|
|
1960
|
+
const looksLikeCarPath = !target.startsWith("ipab://") &&
|
|
1961
|
+
!target.startsWith("builtin:") &&
|
|
1962
|
+
target.toLowerCase().endsWith(".car");
|
|
1963
|
+
if (looksLikeCarPath) {
|
|
1964
|
+
const resolvedCar = resolve(target);
|
|
1965
|
+
let isLocalFile = false;
|
|
1966
|
+
try {
|
|
1967
|
+
isLocalFile = (await lstat(resolvedCar)).isFile();
|
|
1968
|
+
}
|
|
1969
|
+
catch {
|
|
1970
|
+
isLocalFile = false;
|
|
1971
|
+
}
|
|
1972
|
+
if (isLocalFile) {
|
|
1973
|
+
const [{ inspectBundle }, { message }] = await Promise.all([
|
|
1974
|
+
import("./authoring.js"),
|
|
1975
|
+
import("./errors.js"),
|
|
1976
|
+
]);
|
|
1977
|
+
const controller = new AbortController();
|
|
1978
|
+
let cancelled = 0;
|
|
1979
|
+
const interrupt = () => {
|
|
1980
|
+
cancelled = 130;
|
|
1981
|
+
controller.abort(new Error("Interrupted."));
|
|
1982
|
+
};
|
|
1983
|
+
const terminate = () => {
|
|
1984
|
+
cancelled = 143;
|
|
1985
|
+
controller.abort(new Error("Terminated."));
|
|
1986
|
+
};
|
|
1987
|
+
process.once("SIGINT", interrupt);
|
|
1988
|
+
process.once("SIGTERM", terminate);
|
|
1989
|
+
try {
|
|
1990
|
+
const result = await inspectBundle(resolvedCar, {
|
|
1991
|
+
signal: controller.signal,
|
|
1992
|
+
diagnostic: (text) => {
|
|
1993
|
+
io.err(text);
|
|
1994
|
+
},
|
|
1995
|
+
});
|
|
1996
|
+
controller.signal.throwIfAborted();
|
|
1997
|
+
const manifest = result.manifest;
|
|
1998
|
+
const human = `Kind: ${result.kind}\n${manifest ? `Title: ${printable(manifest.title)}\nEntry: ${manifest.entry}\nType file: ${manifest.type}\n` : ""}Type CID: ${result.schemaCid}\nContent type: ${result.type.contentType}\nDefinition validation: passed\nStorage verification: ${result.validation.storage}\nEntry validation: ${result.validation.entry?.status ?? "not-applicable"}`;
|
|
1999
|
+
io.out(parsed.flags.json ? JSON.stringify(result) : human);
|
|
2000
|
+
return 0;
|
|
2001
|
+
}
|
|
2002
|
+
catch (cause) {
|
|
2003
|
+
if (cancelled) {
|
|
2004
|
+
io.err(message(cause));
|
|
2005
|
+
return cancelled;
|
|
2006
|
+
}
|
|
2007
|
+
throw cause;
|
|
2008
|
+
}
|
|
2009
|
+
finally {
|
|
2010
|
+
process.removeListener("SIGINT", interrupt);
|
|
2011
|
+
process.removeListener("SIGTERM", terminate);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
// All remaining commands go through the local Daemon HTTP loopback API.
|
|
2017
|
+
cliHandle = await openCliClient(stateDir, env, parsed.flags, (text, prog) => {
|
|
2018
|
+
io.err(text, prog);
|
|
2019
|
+
}, { lightweight: parsed.path === "swarm list" });
|
|
2020
|
+
const { client } = cliHandle;
|
|
1823
2021
|
const emit = (result, human) => {
|
|
1824
2022
|
io.out(parsed.flags.json ? JSON.stringify(result) : human);
|
|
1825
2023
|
};
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
},
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
forceRefresh: parsed.options.refresh || parsed.options.force
|
|
1865
|
-
? true
|
|
1866
|
-
: parsed.options["no-refresh"] || parsed.options["no-force"]
|
|
1867
|
-
? false
|
|
1868
|
-
: Boolean(value("swarm.forceRefresh")),
|
|
1869
|
-
diagnostic: (text) => {
|
|
1870
|
-
io.err(text);
|
|
1871
|
-
},
|
|
1872
|
-
...(typeof value("pointers.service") === "string"
|
|
1873
|
-
? { pointerService: String(value("pointers.service")) }
|
|
1874
|
-
: {}),
|
|
1875
|
-
...(typeof value("pointers.apiKey") === "string"
|
|
1876
|
-
? { pointerApiKey: String(value("pointers.apiKey")) }
|
|
1877
|
-
: {}),
|
|
2024
|
+
if (parsed.path === "daemon ui") {
|
|
2025
|
+
const { openLoopbackUrl } = await import("./daemon.js");
|
|
2026
|
+
const live = await client.resolveEndpoint();
|
|
2027
|
+
const endpoint = {
|
|
2028
|
+
pid: live.pid,
|
|
2029
|
+
port: live.port,
|
|
2030
|
+
url: live.url,
|
|
2031
|
+
stateDir: live.stateDir,
|
|
2032
|
+
};
|
|
2033
|
+
const opened = Boolean(parsed.options.open);
|
|
2034
|
+
if (opened)
|
|
2035
|
+
openLoopbackUrl(endpoint.url);
|
|
2036
|
+
emit({ ...endpoint, opened }, opened ? `Opened daemon status UI: ${endpoint.url}` : endpoint.url);
|
|
2037
|
+
return 0;
|
|
2038
|
+
}
|
|
2039
|
+
const includeConfigSecrets = ![
|
|
2040
|
+
"swarm members",
|
|
2041
|
+
"profile",
|
|
2042
|
+
"swarm status",
|
|
2043
|
+
"swarm set",
|
|
2044
|
+
].includes(parsed.path);
|
|
2045
|
+
const [configSnapshot, swarmsSnapshot] = await Promise.all([
|
|
2046
|
+
client.host.getConfig(undefined, {
|
|
2047
|
+
includeSecrets: includeConfigSecrets,
|
|
2048
|
+
}),
|
|
2049
|
+
client.swarms.list(),
|
|
2050
|
+
]);
|
|
2051
|
+
const registeredSwarms = swarmsSnapshot.swarms;
|
|
2052
|
+
const resolveSwarm = (reference) => resolveSwarmFromList(registeredSwarms, reference);
|
|
2053
|
+
const savedConfig = configSnapshot.saved ?? {};
|
|
2054
|
+
const computedItems = effectiveConfig(savedConfig, parsed.flags, env, resolveSwarm);
|
|
2055
|
+
const items = computedItems.map((item) => {
|
|
2056
|
+
if (item.key === "pointers.apiKey") {
|
|
2057
|
+
const fromDaemon = configSnapshot.items.find((entry) => entry.key === "pointers.apiKey");
|
|
2058
|
+
if (fromDaemon && item.source === "default")
|
|
2059
|
+
return fromDaemon;
|
|
2060
|
+
}
|
|
2061
|
+
return visibleConfig(item);
|
|
1878
2062
|
});
|
|
1879
|
-
const
|
|
1880
|
-
|
|
1881
|
-
const
|
|
2063
|
+
const value = (key) => items.find((item) => item.key === key).value;
|
|
2064
|
+
const selection = (savedOverride) => {
|
|
2065
|
+
const saved = savedOverride !== undefined
|
|
2066
|
+
? { ...savedConfig, "swarm.default": savedOverride }
|
|
2067
|
+
: savedConfig;
|
|
2068
|
+
const current = effectiveConfig(saved, parsed.flags, env, resolveSwarm).find((item) => item.key === "swarm.default");
|
|
1882
2069
|
return {
|
|
1883
|
-
savedCurrent: saved["swarm.default"]
|
|
1884
|
-
|
|
2070
|
+
savedCurrent: saved["swarm.default"] === undefined
|
|
2071
|
+
? null
|
|
2072
|
+
: saved["swarm.default"],
|
|
2073
|
+
effectiveCurrent: current.value === null ? null : String(current.value),
|
|
1885
2074
|
source: current.source,
|
|
1886
2075
|
};
|
|
1887
2076
|
};
|
|
2077
|
+
const selectedSwarm = selection().effectiveCurrent ?? undefined;
|
|
2078
|
+
const requireSwarm = () => {
|
|
2079
|
+
if (!selectedSwarm)
|
|
2080
|
+
syntax("Select a Swarm with ipab --swarm URL_OR_ALIAS, or save a default with ipab swarm use URL_OR_ALIAS.");
|
|
2081
|
+
return selectedSwarm;
|
|
2082
|
+
};
|
|
2083
|
+
const explicitRefresh = parsed.options.refresh || parsed.options.force
|
|
2084
|
+
? true
|
|
2085
|
+
: parsed.options["no-refresh"] || parsed.options["no-force"]
|
|
2086
|
+
? false
|
|
2087
|
+
: undefined;
|
|
2088
|
+
const stateDirectory = configSnapshot.stateDir ?? stateDir;
|
|
1888
2089
|
if (parsed.path === "open" || parsed.path.startsWith("register ")) {
|
|
1889
|
-
if (
|
|
1890
|
-
io.err(`Legacy User registrations are inactive. ${
|
|
2090
|
+
if (configSnapshot.legacyRegistrationCount)
|
|
2091
|
+
io.err(`Legacy User registrations are inactive. ${configSnapshot.legacyRegistrationCount} entries are preserved in legacy_user_registrations in the state database under ${stateDirectory}; nothing was uploaded or deleted. Custom per-association argv is unsupported. Review the archived values and explicitly run ipab register set TYPE_CID APP_CID --swarm URL_OR_ALIAS to publish only intended associations.`);
|
|
1891
2092
|
}
|
|
1892
|
-
if (
|
|
1893
|
-
io.err(`Legacy local pin names are inactive: ${
|
|
2093
|
+
if (configSnapshot.legacyPinCount)
|
|
2094
|
+
io.err(`Legacy local pin names are inactive: ${configSnapshot.legacyPinCount} records are preserved in legacy_named_pins under ${stateDirectory}. Retention and original Store owners are unchanged; inspect ipab pin list and release intended archived holders with ipab unpin EXACT_CID.`);
|
|
2095
|
+
const [first, second] = parsed.positional;
|
|
1894
2096
|
if (parsed.path === "swarm list") {
|
|
1895
|
-
const result = { swarms:
|
|
2097
|
+
const result = { swarms: registeredSwarms, ...selection() };
|
|
1896
2098
|
emit({
|
|
1897
2099
|
...result,
|
|
1898
2100
|
swarms: result.swarms.map((entry) => ({
|
|
@@ -1914,114 +2116,102 @@ async function performCli(argv, io, env) {
|
|
|
1914
2116
|
].join("\n"));
|
|
1915
2117
|
return 0;
|
|
1916
2118
|
}
|
|
1917
|
-
const [{ ContentError, IpfsStore }, { ContentBundleError, openBundle }, { message }, { filters, listHistory, selectedIds, Ownership, recoverInactive, removeHistory, }, { execute }, { validatedBundle }, { buildBundle, inspectBundle, importBundle, nodeError, resolveLocalBundleInput, snapshotLocalBundle, }, { initApp }, { assembleBundle }, { getBundle }, { ensureDaemon, serveDaemon }, { keyId }, { createSwarm, swarmDaemon, requestMembership, approveMembership, grantPivotAuthority, exportRequest, removeMember, resumeRemoval, updateProfile, accountProfile, updateAccountProfile, swarmMembers, inspectSwarmStatus, verifiedRequest, verifiedRequestStream, membershipRequestSummary, updateSwarm, searchNames, resolveReference, publish, pinNameSubscription, pinReference, swarmRegistrations, swarmAssociation, setSwarmAssociation, removeSwarmAssociation, resolveTemplateSelector, swarmTemplates, setSwarmTemplate, removeSwarmTemplate, artifactValue, swarmTypeSkills, swarmTypeSkill, setSwarmSkill, removeSwarmSkill, }, { schemaAlias }, { unpin, pinDetails }, { publicationSource }, { templateRenderExample, templateOutputTree, templateParameterRows }, { logFiles }, { manageSkills, syncDaemonSwarm },] = await Promise.all([
|
|
1918
|
-
import("@ipab/ipfs-store"),
|
|
1919
|
-
import("@ipab/bundle"),
|
|
1920
|
-
import("./errors.js"),
|
|
1921
|
-
import("./history.js"),
|
|
1922
|
-
import("./runtime.js"),
|
|
1923
|
-
import("./space.js"),
|
|
1924
|
-
import("./authoring.js"),
|
|
1925
|
-
import("./app-authoring.js"),
|
|
1926
|
-
import("./assembly.js"),
|
|
1927
|
-
import("./get.js"),
|
|
1928
|
-
import("./daemon.js"),
|
|
1929
|
-
import("@ipab/bundle/pointer/crypto"),
|
|
1930
|
-
import("./swarm.js"),
|
|
1931
|
-
import("./app-definition.js"),
|
|
1932
|
-
import("./pins.js"),
|
|
1933
|
-
import("./publish-source.js"),
|
|
1934
|
-
import("./template-presentation.js"),
|
|
1935
|
-
import("./logs.js"),
|
|
1936
|
-
import("./skills.js"),
|
|
1937
|
-
]);
|
|
1938
|
-
const filter = parsed.path.startsWith("history ")
|
|
1939
|
-
? filters(state, parsed.options)
|
|
1940
|
-
: {};
|
|
1941
2119
|
if (parsed.path.startsWith("templates ") &&
|
|
1942
2120
|
parsed.path !== "templates render") {
|
|
1943
2121
|
const configUrl = requireSwarm();
|
|
1944
|
-
store = new IpfsStore(await storeConfiguration(value("store.gateway")));
|
|
1945
|
-
const context = swarmContext();
|
|
1946
2122
|
const expected = typeof parsed.options.expect === "string"
|
|
1947
2123
|
? parsed.options.expect
|
|
1948
2124
|
: undefined;
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
io.out([
|
|
1975
|
-
`${printable(item.selector)} — ${printable(item.title)}`,
|
|
1976
|
-
printable(item.description) || "(No description.)",
|
|
1977
|
-
"",
|
|
1978
|
-
"Location",
|
|
1979
|
-
` Swarm: ${printable(swarm)}`,
|
|
1980
|
-
` Name: ${printable(item.name)}`,
|
|
1981
|
-
"",
|
|
1982
|
-
`Create a project (${shell === "powershell" ? "PowerShell" : "POSIX shell"})`,
|
|
1983
|
-
` ${templateRenderExample(reference, swarm, item.definition, shell)}`,
|
|
1984
|
-
" Replace example parameter values as needed. No code is run by show.",
|
|
1985
|
-
"",
|
|
1986
|
-
"Parameters",
|
|
1987
|
-
table(["NAME", "TYPE", "REQUIRED", "DEFAULT", "INPUT"], templateParameterRows(item.definition), "No parameters declared."),
|
|
1988
|
-
"Required means an input is needed when no default is declared.",
|
|
1989
|
-
"",
|
|
1990
|
-
"Output files (from project/)",
|
|
1991
|
-
" my-project/",
|
|
1992
|
-
...tree.entries.map((entry) => `${" ".repeat(entry.path.split("/").length + 1)}${printable(entry.path.split("/").at(-1))}${entry.kind === "directory" ? "/" : ""}`),
|
|
1993
|
-
...(tree.truncated
|
|
1994
|
-
? [
|
|
1995
|
-
` ... truncated: ${tree.truncated}; more files may exist.`,
|
|
1996
|
-
]
|
|
1997
|
-
: tree.entries.length
|
|
1998
|
-
? []
|
|
1999
|
-
: [" (no output files)"]),
|
|
2000
|
-
"",
|
|
2001
|
-
"Versions",
|
|
2002
|
-
` Template CID: ${item.templateCid}`,
|
|
2003
|
-
` Reference: ${reference}`,
|
|
2004
|
-
...(item.targetCid !== item.templateCid
|
|
2005
|
-
? [` Target CID (--expect): ${item.targetCid}`]
|
|
2006
|
-
: []),
|
|
2007
|
-
].join("\n"));
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
else if (parsed.path === "templates set") {
|
|
2011
|
-
const item = await setSwarmTemplate(context, configUrl, first, second, expected);
|
|
2012
|
-
emit(item, `${item.reference} → ${item.targetCid} (Template ${item.templateCid})`);
|
|
2013
|
-
}
|
|
2125
|
+
if (parsed.path === "templates list") {
|
|
2126
|
+
const response = (await client.swarms.fsLs({
|
|
2127
|
+
swarm: configUrl,
|
|
2128
|
+
kind: "templates",
|
|
2129
|
+
refresh: explicitRefresh,
|
|
2130
|
+
}, { ndjson: true }));
|
|
2131
|
+
emit({ items: response.items }, `Swarm: ${response.alias ? printable(response.alias) : "(no local alias)"}\nConfig URL: ${configUrl}\nTemplates: ${response.items.length}\n\n${table(["NAME", "TITLE", "TARGET CID", "TEMPLATE CID"], response.items.map((item) => [
|
|
2132
|
+
item.selector,
|
|
2133
|
+
item.title,
|
|
2134
|
+
item.targetCid,
|
|
2135
|
+
item.templateCid,
|
|
2136
|
+
]), "No templates registered in this Swarm.\nAdd a template: ipab templates set NAME SOURCE")}`);
|
|
2137
|
+
}
|
|
2138
|
+
else if (parsed.path === "templates show") {
|
|
2139
|
+
const { templateRenderExample, templateParameterRows } = await import("./template-presentation.js");
|
|
2140
|
+
const response = (await client.swarms.fsStat({
|
|
2141
|
+
swarm: configUrl,
|
|
2142
|
+
kind: "template",
|
|
2143
|
+
name: first,
|
|
2144
|
+
includeTree: !parsed.flags.json,
|
|
2145
|
+
refresh: explicitRefresh,
|
|
2146
|
+
}, { ndjson: true }));
|
|
2147
|
+
const { item, tree, alias } = response;
|
|
2148
|
+
if (parsed.flags.json)
|
|
2149
|
+
io.out(JSON.stringify(item));
|
|
2014
2150
|
else {
|
|
2015
|
-
const
|
|
2016
|
-
|
|
2151
|
+
const previewTree = tree ?? { entries: [], truncated: null };
|
|
2152
|
+
const swarm = alias ?? configUrl;
|
|
2153
|
+
const reference = formatNameReference(swarm, item.name);
|
|
2154
|
+
const shell = process.platform === "win32" ? "powershell" : "posix";
|
|
2155
|
+
io.out([
|
|
2156
|
+
`${printable(item.selector)} — ${printable(item.title)}`,
|
|
2157
|
+
printable(item.description) || "(No description.)",
|
|
2158
|
+
"",
|
|
2159
|
+
"Location",
|
|
2160
|
+
` Swarm: ${printable(swarm)}`,
|
|
2161
|
+
` Name: ${printable(item.name)}`,
|
|
2162
|
+
"",
|
|
2163
|
+
`Create a project (${shell === "powershell" ? "PowerShell" : "POSIX shell"})`,
|
|
2164
|
+
` ${templateRenderExample(reference, swarm, item.definition, shell)}`,
|
|
2165
|
+
" Replace example parameter values as needed. No code is run by show.",
|
|
2166
|
+
"",
|
|
2167
|
+
"Parameters",
|
|
2168
|
+
table(["NAME", "TYPE", "REQUIRED", "DEFAULT", "INPUT"], templateParameterRows(item.definition), "No parameters declared."),
|
|
2169
|
+
"Required means an input is needed when no default is declared.",
|
|
2170
|
+
"",
|
|
2171
|
+
"Output files (from project/)",
|
|
2172
|
+
" my-project/",
|
|
2173
|
+
...previewTree.entries.map((entry) => `${" ".repeat(entry.path.split("/").length + 1)}${printable(entry.path.split("/").at(-1))}${entry.kind === "directory" ? "/" : ""}`),
|
|
2174
|
+
...(previewTree.truncated
|
|
2175
|
+
? [
|
|
2176
|
+
` ... truncated: ${previewTree.truncated}; more files may exist.`,
|
|
2177
|
+
]
|
|
2178
|
+
: previewTree.entries.length
|
|
2179
|
+
? []
|
|
2180
|
+
: [" (no output files)"]),
|
|
2181
|
+
"",
|
|
2182
|
+
"Versions",
|
|
2183
|
+
` Template CID: ${item.templateCid}`,
|
|
2184
|
+
` Reference: ${reference}`,
|
|
2185
|
+
...(item.targetCid !== item.templateCid
|
|
2186
|
+
? [` Target CID (--expect): ${item.targetCid}`]
|
|
2187
|
+
: []),
|
|
2188
|
+
].join("\n"));
|
|
2017
2189
|
}
|
|
2018
2190
|
}
|
|
2019
|
-
|
|
2020
|
-
await
|
|
2191
|
+
else if (parsed.path === "templates set") {
|
|
2192
|
+
const source = await resolveLocalPathIfPresent(second);
|
|
2193
|
+
const item = (await client.swarms.fsSet({
|
|
2194
|
+
swarm: configUrl,
|
|
2195
|
+
kind: "template",
|
|
2196
|
+
name: first,
|
|
2197
|
+
source,
|
|
2198
|
+
expect: expected,
|
|
2199
|
+
}, { ndjson: true }));
|
|
2200
|
+
emit(item, `${item.reference} → ${item.targetCid} (Template ${item.templateCid})`);
|
|
2201
|
+
}
|
|
2202
|
+
else {
|
|
2203
|
+
const item = (await client.swarms.fsRm({
|
|
2204
|
+
swarm: configUrl,
|
|
2205
|
+
kind: "template",
|
|
2206
|
+
name: first,
|
|
2207
|
+
expect: expected,
|
|
2208
|
+
}, { ndjson: true }));
|
|
2209
|
+
emit({ removed: item }, `Removed ${item.reference}; content and history are retained.`);
|
|
2021
2210
|
}
|
|
2022
2211
|
return 0;
|
|
2023
2212
|
}
|
|
2024
2213
|
if (parsed.path.startsWith("register ")) {
|
|
2214
|
+
const { message } = await import("./errors.js");
|
|
2025
2215
|
const references = parsed.registrySwarms?.length
|
|
2026
2216
|
? parsed.registrySwarms
|
|
2027
2217
|
: selectedSwarm
|
|
@@ -2030,69 +2220,68 @@ async function performCli(argv, io, env) {
|
|
|
2030
2220
|
if (!references.length)
|
|
2031
2221
|
throw new HostError("Register requires a selected Swarm. Pass --swarm URL_OR_ALIAS, or save a default with ipab swarm use URL_OR_ALIAS.");
|
|
2032
2222
|
const targets = [
|
|
2033
|
-
...new Set(references.map((reference) =>
|
|
2223
|
+
...new Set(references.map((reference) => resolveSwarm(reference))),
|
|
2034
2224
|
];
|
|
2035
|
-
const schema = first
|
|
2036
|
-
? state.resolve(schemaAlias(first), true)
|
|
2037
|
-
: undefined;
|
|
2038
2225
|
const results = [];
|
|
2039
2226
|
const completed = [];
|
|
2040
2227
|
const human = [];
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
? await resolveLocalBundleInput(second)
|
|
2228
|
+
const resolvedApp = parsed.path === "register set"
|
|
2229
|
+
? await resolveLocalPathIfPresent(second)
|
|
2044
2230
|
: undefined;
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2231
|
+
if (parsed.path === "register set" && targets.length > 1) {
|
|
2232
|
+
const batch = (await client.swarms.fsSet({
|
|
2233
|
+
swarm: targets[0],
|
|
2234
|
+
swarms: targets,
|
|
2235
|
+
kind: "register",
|
|
2236
|
+
schema: first,
|
|
2237
|
+
app: resolvedApp,
|
|
2238
|
+
argv: parsed.template ?? ["%"],
|
|
2239
|
+
replace: Boolean(parsed.options.replace),
|
|
2240
|
+
}, { ndjson: true }));
|
|
2241
|
+
for (let i = 0; i < targets.length; i++) {
|
|
2242
|
+
const association = batch.associations[i];
|
|
2243
|
+
results.push({ association });
|
|
2244
|
+
human.push(`${targets[i]}: ${association.schemaCid} → ${association.appCid} ${JSON.stringify(association.argv)}`);
|
|
2056
2245
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
? (await resolveReference(context, second, configUrl, (reference) => state.resolve(reference))).cid
|
|
2072
|
-
: state.resolve(second));
|
|
2073
|
-
const association = await setSwarmAssociation(context, configUrl, createAssociation(schema, appCid, parsed.template ?? ["%"]), Boolean(parsed.options.replace));
|
|
2074
|
-
results.push({ association });
|
|
2075
|
-
human.push(`${configUrl}: ${association.schemaCid} → ${association.appCid} ${JSON.stringify(association.argv)}`);
|
|
2076
|
-
}
|
|
2077
|
-
else {
|
|
2078
|
-
const removed = await removeSwarmAssociation(context, configUrl, schema);
|
|
2079
|
-
results.push({ removed: [removed] });
|
|
2080
|
-
human.push(`${configUrl}: removed association for ${removed}.`);
|
|
2081
|
-
}
|
|
2082
|
-
completed.push(configUrl);
|
|
2246
|
+
emit({
|
|
2247
|
+
swarms: results.map((result, index) => ({
|
|
2248
|
+
configUrl: targets[index],
|
|
2249
|
+
...result,
|
|
2250
|
+
})),
|
|
2251
|
+
}, human.join("\n\n"));
|
|
2252
|
+
return 0;
|
|
2253
|
+
}
|
|
2254
|
+
for (const configUrl of targets) {
|
|
2255
|
+
try {
|
|
2256
|
+
if (parsed.path === "register list") {
|
|
2257
|
+
const response = (await client.swarms.fsLs({ swarm: configUrl, kind: "register" }, { ndjson: true }));
|
|
2258
|
+
results.push({ items: response.items });
|
|
2259
|
+
human.push(`Swarm: ${response.alias ? printable(response.alias) : "(no local alias)"}\nConfig URL: ${configUrl}\nAssociations: ${response.items.length}\n\n${table(["TYPE CID", "APP CID"], response.items.map((item) => [item.schemaCid, item.appCid]), "No associations registered in this Swarm.\nRegister an App: ipab register set TYPE_CID APP_CID --swarm URL_OR_ALIAS")}`);
|
|
2083
2260
|
}
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
:
|
|
2261
|
+
else if (parsed.path === "register set") {
|
|
2262
|
+
const association = (await client.swarms.fsSet({
|
|
2263
|
+
swarm: configUrl,
|
|
2264
|
+
kind: "register",
|
|
2265
|
+
schema: first,
|
|
2266
|
+
app: resolvedApp,
|
|
2267
|
+
argv: parsed.template ?? ["%"],
|
|
2268
|
+
replace: Boolean(parsed.options.replace),
|
|
2269
|
+
}, { ndjson: true }));
|
|
2270
|
+
results.push({ association });
|
|
2271
|
+
human.push(`${configUrl}: ${association.schemaCid} → ${association.appCid} ${JSON.stringify(association.argv)}`);
|
|
2088
2272
|
}
|
|
2089
|
-
|
|
2090
|
-
await
|
|
2273
|
+
else {
|
|
2274
|
+
const response = (await client.swarms.fsRm({ swarm: configUrl, kind: "register", schema: first }, { ndjson: true }));
|
|
2275
|
+
results.push({ removed: [response.removed] });
|
|
2276
|
+
human.push(`${configUrl}: removed association for ${response.removed}.`);
|
|
2091
2277
|
}
|
|
2278
|
+
completed.push(configUrl);
|
|
2279
|
+
}
|
|
2280
|
+
catch (cause) {
|
|
2281
|
+
throw new HostError(parsed.path === "register list"
|
|
2282
|
+
? `Cannot list associations for Swarm ${configUrl}: ${message(cause)}`
|
|
2283
|
+
: `Registry operation failed for ${configUrl}: ${message(cause)}. Completed Swarms: ${completed.length ? completed.join(", ") : "(none)"}. Multiple Swarm edits are not atomic.`, cause instanceof HostError ? cause.exitCode : 1, cause instanceof HostError ? cause.code : "REGISTRY_FAILED", "publication");
|
|
2092
2284
|
}
|
|
2093
|
-
}
|
|
2094
|
-
finally {
|
|
2095
|
-
await registerOwner?.release();
|
|
2096
2285
|
}
|
|
2097
2286
|
emit({
|
|
2098
2287
|
swarms: results.map((result, index) => ({
|
|
@@ -2104,8 +2293,6 @@ async function performCli(argv, io, env) {
|
|
|
2104
2293
|
}
|
|
2105
2294
|
switch (parsed.path) {
|
|
2106
2295
|
case "profile": {
|
|
2107
|
-
const context = swarmContext();
|
|
2108
|
-
readContext = context;
|
|
2109
2296
|
const changes = {
|
|
2110
2297
|
...(typeof parsed.options.name === "string"
|
|
2111
2298
|
? { name: parsed.options.name }
|
|
@@ -2115,11 +2302,15 @@ async function performCli(argv, io, env) {
|
|
|
2115
2302
|
: {}),
|
|
2116
2303
|
};
|
|
2117
2304
|
if (!Object.keys(changes).length) {
|
|
2118
|
-
const profile = await
|
|
2305
|
+
const profile = (await client.swarms.identity({
|
|
2306
|
+
ndjson: true,
|
|
2307
|
+
}));
|
|
2119
2308
|
emit({ profile, localPersisted: profile.updatedAt !== null }, `Name: ${printable(profile.name)}\nDescription: ${printable(profile.description)}\nPublic key: ${profile.publicKey}`);
|
|
2120
2309
|
}
|
|
2121
2310
|
else {
|
|
2122
|
-
const result = await
|
|
2311
|
+
const result = (await client.swarms.governance("profile", changes, {
|
|
2312
|
+
ndjson: true,
|
|
2313
|
+
}));
|
|
2123
2314
|
emit(result, [
|
|
2124
2315
|
`Name: ${printable(result.profile.name)}`,
|
|
2125
2316
|
`Description: ${printable(result.profile.description)}`,
|
|
@@ -2134,25 +2325,29 @@ async function performCli(argv, io, env) {
|
|
|
2134
2325
|
break;
|
|
2135
2326
|
}
|
|
2136
2327
|
case "swarm use": {
|
|
2137
|
-
|
|
2138
|
-
const
|
|
2328
|
+
const resolvedUrl = resolveSwarm(first);
|
|
2329
|
+
const registered = registeredSwarms.some((entry) => entry.cid === resolvedUrl);
|
|
2330
|
+
if (!registered) {
|
|
2331
|
+
throw new HostError(`Unknown Swarm "${first}". Run ipab swarm list or register it with ipab swarm set ALIAS CONFIG_URL.`);
|
|
2332
|
+
}
|
|
2333
|
+
await client.host.setConfig("swarm.default", resolvedUrl, {
|
|
2334
|
+
fromString: true,
|
|
2335
|
+
});
|
|
2336
|
+
const result = selection(resolvedUrl);
|
|
2139
2337
|
emit(result, `Saved current swarm: ${result.savedCurrent}`);
|
|
2140
2338
|
if (result.source === "flag" || result.source === "env")
|
|
2141
2339
|
io.err(`The saved default is overridden by ${result.source}: ${result.effectiveCurrent}.`);
|
|
2142
2340
|
break;
|
|
2143
2341
|
}
|
|
2144
2342
|
case "swarm remove": {
|
|
2145
|
-
const
|
|
2146
|
-
emit({
|
|
2147
|
-
removed,
|
|
2148
|
-
savedCurrent: state.config({ includeSecrets: false })["swarm.default"] ?? null,
|
|
2149
|
-
}, `Removed registration ${removed}. Credentials, content and remote membership are unchanged.`);
|
|
2343
|
+
const result = await client.swarms.remove({ swarm: first });
|
|
2344
|
+
emit(result, `Removed registration ${result.removed}. Credentials, content and remote membership are unchanged.`);
|
|
2150
2345
|
break;
|
|
2151
2346
|
}
|
|
2152
2347
|
case "swarm set": {
|
|
2153
2348
|
swarmAlias(first);
|
|
2154
2349
|
const cid = swarmUrl(second);
|
|
2155
|
-
const previous =
|
|
2350
|
+
const previous = registeredSwarms.find((entry) => entry.alias === first);
|
|
2156
2351
|
if (previous && previous.cid !== cid) {
|
|
2157
2352
|
io.err(`Swarm alias ${first}: ${previous.cid} -> ${cid}`);
|
|
2158
2353
|
if (!parsed.options.yes &&
|
|
@@ -2160,826 +2355,645 @@ async function performCli(argv, io, env) {
|
|
|
2160
2355
|
!(await io.confirm(`Retarget local Swarm alias "${first}" from ${previous.cid} to ${cid}?`))))
|
|
2161
2356
|
throw new HostError("Alias unchanged. Retargeting requires --yes or interactive confirmation.");
|
|
2162
2357
|
}
|
|
2163
|
-
const entry =
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2358
|
+
const entry = await client.swarms.set({
|
|
2359
|
+
alias: first,
|
|
2360
|
+
url: cid,
|
|
2361
|
+
expectedTarget: previous?.cid ?? null,
|
|
2362
|
+
});
|
|
2363
|
+
emit(entry, `Set local swarm alias ${entry.alias} (${cid}).`);
|
|
2169
2364
|
break;
|
|
2170
2365
|
}
|
|
2171
|
-
case "
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
};
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
}
|
|
2188
|
-
finally {
|
|
2189
|
-
process.removeListener("SIGINT", interrupt);
|
|
2190
|
-
process.removeListener("SIGTERM", interrupt);
|
|
2366
|
+
case "fs ls": {
|
|
2367
|
+
const result = await client.swarms.fsLs({
|
|
2368
|
+
swarm: requireSwarm(),
|
|
2369
|
+
path: first,
|
|
2370
|
+
all: Boolean(parsed.options.all),
|
|
2371
|
+
recursive: Boolean(parsed.options.recursive),
|
|
2372
|
+
refresh: explicitRefresh,
|
|
2373
|
+
}, { ndjson: true });
|
|
2374
|
+
const text = result.entries.length
|
|
2375
|
+
? result.entries
|
|
2376
|
+
.map((entry) => `${result.recursive ? entry.path : entry.name}\t${entry.cid ?? "<dir>"}\t${entry.size !== null ? String(entry.size) : entry.kind}`)
|
|
2377
|
+
.join("\n")
|
|
2378
|
+
: "No entries.";
|
|
2379
|
+
emit(result, text);
|
|
2380
|
+
if (result.truncated || result.skippedSubtrees > 0) {
|
|
2381
|
+
io.err(`Listing incomplete: truncated=${String(result.truncated)}, skippedSubtrees=${String(result.skippedSubtrees)}.`);
|
|
2191
2382
|
}
|
|
2192
2383
|
break;
|
|
2193
2384
|
}
|
|
2194
|
-
case "
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
const
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
})
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
break;
|
|
2299
|
-
}
|
|
2300
|
-
if (parsed.path === "swarm replicate") {
|
|
2301
|
-
const { replicateSwarm } = await import("./swarm.js");
|
|
2302
|
-
context.diagnostic = (text) => {
|
|
2303
|
-
io.err(text);
|
|
2304
|
-
};
|
|
2305
|
-
const result = await replicateSwarm(context, requireSwarm(), undefined, {
|
|
2306
|
-
...(typeof parsed.options.pivot === "string"
|
|
2307
|
-
? { pivot: parsed.options.pivot }
|
|
2308
|
-
: {}),
|
|
2309
|
-
});
|
|
2310
|
-
store = context.store;
|
|
2311
|
-
emit(result, [
|
|
2385
|
+
case "fs stat": {
|
|
2386
|
+
const result = await client.swarms.fsStat({
|
|
2387
|
+
swarm: requireSwarm(),
|
|
2388
|
+
path: first,
|
|
2389
|
+
...(explicitRefresh !== undefined
|
|
2390
|
+
? { refresh: explicitRefresh }
|
|
2391
|
+
: {}),
|
|
2392
|
+
}, { ndjson: true });
|
|
2393
|
+
const lines = [
|
|
2394
|
+
`Path: ${result.path || "/"}`,
|
|
2395
|
+
`CID: ${result.cid ?? "(virtual)"}`,
|
|
2396
|
+
`Kind: ${result.kind}`,
|
|
2397
|
+
`Size: ${result.size !== null ? String(result.size) : "unavailable"}`,
|
|
2398
|
+
...(result.kind === "directory" && result.isBundle !== undefined
|
|
2399
|
+
? [`Bundle: ${result.isBundle ? "yes" : "no"}`]
|
|
2400
|
+
: []),
|
|
2401
|
+
...(result.kind === "directory" && result.entryCount !== undefined
|
|
2402
|
+
? [`Entries: ${result.entryCount}`]
|
|
2403
|
+
: []),
|
|
2404
|
+
`Swarm: ${result.swarm}`,
|
|
2405
|
+
`Snapshot: ${result.snapshotVersion === "legacy" ? "legacy (read-only virtual)" : "v7"}`,
|
|
2406
|
+
];
|
|
2407
|
+
emit(result, lines.join("\n"));
|
|
2408
|
+
break;
|
|
2409
|
+
}
|
|
2410
|
+
case "fs set": {
|
|
2411
|
+
const result = await client.swarms.fsSet({
|
|
2412
|
+
swarm: requireSwarm(),
|
|
2413
|
+
path: first,
|
|
2414
|
+
cid: second,
|
|
2415
|
+
...(typeof parsed.options.expect === "string"
|
|
2416
|
+
? { expect: parsed.options.expect }
|
|
2417
|
+
: {}),
|
|
2418
|
+
...(parsed.options.replace ? { replace: true } : {}),
|
|
2419
|
+
}, { ndjson: true });
|
|
2420
|
+
emit(result, result.changed
|
|
2421
|
+
? `Set ${result.path} -> ${result.cid} (HEAD ${result.headCid})`
|
|
2422
|
+
: `Unchanged ${result.path} -> ${result.cid} (HEAD ${result.headCid})`);
|
|
2423
|
+
break;
|
|
2424
|
+
}
|
|
2425
|
+
case "fs rm": {
|
|
2426
|
+
const result = await client.swarms.fsRm({
|
|
2427
|
+
swarm: requireSwarm(),
|
|
2428
|
+
path: first,
|
|
2429
|
+
...(typeof parsed.options.expect === "string"
|
|
2430
|
+
? { expect: parsed.options.expect }
|
|
2431
|
+
: {}),
|
|
2432
|
+
}, { ndjson: true });
|
|
2433
|
+
emit(result, `Removed ${result.path} (was ${result.removedCid}, HEAD ${result.headCid})`);
|
|
2434
|
+
break;
|
|
2435
|
+
}
|
|
2436
|
+
case "swarm replicate": {
|
|
2437
|
+
const result = (await client.swarms.replicate({
|
|
2438
|
+
swarm: requireSwarm(),
|
|
2439
|
+
...(typeof parsed.options.pivot === "string"
|
|
2440
|
+
? { pivot: parsed.options.pivot }
|
|
2441
|
+
: {}),
|
|
2442
|
+
}, { ndjson: true }));
|
|
2443
|
+
emit(result, [
|
|
2444
|
+
`HEAD: ${result.headCid}`,
|
|
2445
|
+
...result.results.map((entry) => `${entry.peerId}: ${entry.status}${entry.error ? ` (${entry.error})` : ""}`),
|
|
2446
|
+
].join("\n"));
|
|
2447
|
+
break;
|
|
2448
|
+
}
|
|
2449
|
+
case "skills show": {
|
|
2450
|
+
const named = parseNameReference(first);
|
|
2451
|
+
const targetSwarm = named?.swarm
|
|
2452
|
+
? resolveSwarm(named.swarm)
|
|
2453
|
+
: requireSwarm();
|
|
2454
|
+
const ref = await resolveLocalPathIfPresent(first);
|
|
2455
|
+
const payload = (await client.swarms.fsStat({
|
|
2456
|
+
swarm: targetSwarm,
|
|
2457
|
+
kind: "skill",
|
|
2458
|
+
ref,
|
|
2459
|
+
...(explicitRefresh !== undefined
|
|
2460
|
+
? { refresh: explicitRefresh }
|
|
2461
|
+
: {}),
|
|
2462
|
+
}, { ndjson: true }));
|
|
2463
|
+
const lines = [
|
|
2464
|
+
`Swarm: ${payload.swarm}`,
|
|
2465
|
+
`Schema: ${payload.schemaCid}`,
|
|
2466
|
+
...(payload.contentCid ? [`Content CID: ${payload.contentCid}`] : []),
|
|
2467
|
+
`Skill: ${payload.identity}`,
|
|
2468
|
+
`Skill CID: ${payload.cid}`,
|
|
2469
|
+
`Path: ${payload.name}`,
|
|
2470
|
+
`Description: ${payload.description}`,
|
|
2471
|
+
];
|
|
2472
|
+
emit(payload, lines.join("\n"));
|
|
2473
|
+
break;
|
|
2474
|
+
}
|
|
2475
|
+
case "skills set": {
|
|
2476
|
+
const targetSwarm = requireSwarm();
|
|
2477
|
+
const skill = await resolveLocalPathIfPresent(first);
|
|
2478
|
+
const result = (await client.swarms.fsSet({
|
|
2479
|
+
swarm: targetSwarm,
|
|
2480
|
+
kind: "skill",
|
|
2481
|
+
skill,
|
|
2482
|
+
global: Boolean(parsed.options.global),
|
|
2483
|
+
types: parsed.types ?? [],
|
|
2484
|
+
replace: Boolean(parsed.options.replace),
|
|
2485
|
+
}, { ndjson: true }));
|
|
2486
|
+
const text = result.changed
|
|
2487
|
+
? [
|
|
2488
|
+
`Skill: ${result.identity} (${result.cid})`,
|
|
2312
2489
|
`HEAD: ${result.headCid}`,
|
|
2313
|
-
...result.
|
|
2314
|
-
|
|
2315
|
-
|
|
2490
|
+
...result.targets.map((target) => {
|
|
2491
|
+
const status = !target.changed
|
|
2492
|
+
? "unchanged"
|
|
2493
|
+
: target.previousCid
|
|
2494
|
+
? "updated"
|
|
2495
|
+
: "created";
|
|
2496
|
+
return target.scope === "global"
|
|
2497
|
+
? ` global -> ${target.name} (${status})`
|
|
2498
|
+
: ` type ${target.schemaCid} -> ${target.name} (${status})`;
|
|
2499
|
+
}),
|
|
2500
|
+
].join("\n")
|
|
2501
|
+
: `Unchanged: ${result.identity} (${result.cid}) (HEAD ${result.headCid})`;
|
|
2502
|
+
emit(result, text);
|
|
2503
|
+
break;
|
|
2504
|
+
}
|
|
2505
|
+
case "skills remove": {
|
|
2506
|
+
const targetSwarm = requireSwarm();
|
|
2507
|
+
const globalName = typeof parsed.options.global === "string"
|
|
2508
|
+
? parsed.options.global
|
|
2509
|
+
: undefined;
|
|
2510
|
+
const result = (await client.swarms.fsRm({
|
|
2511
|
+
swarm: targetSwarm,
|
|
2512
|
+
kind: "skill",
|
|
2513
|
+
...(globalName !== undefined ? { globalName } : {}),
|
|
2514
|
+
types: parsed.types ?? [],
|
|
2515
|
+
}, { ndjson: true }));
|
|
2516
|
+
const lines = [
|
|
2517
|
+
`Removed ${result.removed.length} Skill association(s) (HEAD ${result.headCid}):`,
|
|
2518
|
+
...result.removed.map((entry) => entry.scope === "global"
|
|
2519
|
+
? ` global ${entry.name} (was ${entry.removedCid})`
|
|
2520
|
+
: ` type ${entry.schemaCid} ${entry.name} (was ${entry.removedCid})`),
|
|
2521
|
+
];
|
|
2522
|
+
emit(result, lines.join("\n"));
|
|
2523
|
+
break;
|
|
2524
|
+
}
|
|
2525
|
+
case "skills list": {
|
|
2526
|
+
const targetSwarm = requireSwarm();
|
|
2527
|
+
const result = (await client.swarms.fsLs({
|
|
2528
|
+
swarm: targetSwarm,
|
|
2529
|
+
kind: "skills",
|
|
2530
|
+
names: parsed.positional,
|
|
2531
|
+
agents: parsed.agents ?? [],
|
|
2532
|
+
refresh: explicitRefresh,
|
|
2533
|
+
}, { ndjson: true }));
|
|
2534
|
+
const globalLines = [
|
|
2535
|
+
table(["NAME", "PAYLOAD CID", "INSTALL NAME", "STATUS"], result.items.map((skill) => [
|
|
2536
|
+
skill.name,
|
|
2537
|
+
skill.cid,
|
|
2538
|
+
skill.identity,
|
|
2539
|
+
skill.status,
|
|
2540
|
+
]), "No Global Skills."),
|
|
2541
|
+
...result.items.flatMap((skill) => skill.problems),
|
|
2542
|
+
...result.orphaned.map((skill) => `Source removed: ${skill.name} ${skill.cid} (${skill.path}); installation retained.`),
|
|
2543
|
+
];
|
|
2544
|
+
const typeLines = [
|
|
2545
|
+
"Type Skills:",
|
|
2546
|
+
table(["TYPE CID", "SKILL NAME", "SKILL CID"], result.typeSkills.map((entry) => [
|
|
2547
|
+
entry.schemaCid,
|
|
2548
|
+
entry.identity,
|
|
2549
|
+
entry.cid,
|
|
2550
|
+
]), "No Type Skills."),
|
|
2551
|
+
];
|
|
2552
|
+
emit(result, [...globalLines, "", ...typeLines].join("\n"));
|
|
2553
|
+
if (!result.ok)
|
|
2554
|
+
return 1;
|
|
2555
|
+
break;
|
|
2556
|
+
}
|
|
2557
|
+
case "skills sync": {
|
|
2558
|
+
const targetSwarm = requireSwarm();
|
|
2559
|
+
const syncParams = {
|
|
2560
|
+
swarm: targetSwarm,
|
|
2561
|
+
names: parsed.positional,
|
|
2562
|
+
agents: parsed.agents ?? [],
|
|
2563
|
+
overrideExisting: Boolean(parsed.options["override-existing"]),
|
|
2564
|
+
refresh: explicitRefresh,
|
|
2565
|
+
};
|
|
2566
|
+
let result;
|
|
2567
|
+
if (parsed.options["dry-run"] || parsed.options.yes || !io.tty) {
|
|
2568
|
+
result = (await client.host.syncSkills({
|
|
2569
|
+
...syncParams,
|
|
2570
|
+
dryRun: Boolean(parsed.options["dry-run"]),
|
|
2571
|
+
yes: Boolean(parsed.options.yes),
|
|
2572
|
+
}, { ndjson: true }));
|
|
2316
2573
|
}
|
|
2317
|
-
|
|
2318
|
-
const
|
|
2319
|
-
|
|
2320
|
-
:
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
let contentCid;
|
|
2334
|
-
let reference;
|
|
2335
|
-
let association;
|
|
2336
|
-
if (named) {
|
|
2337
|
-
targetSwarm = named.swarm
|
|
2338
|
-
? state.resolveSwarm(named.swarm)
|
|
2339
|
-
: requireSwarm();
|
|
2340
|
-
const resolved = await resolveReference(context, first, targetSwarm, (ref) => state.resolve(ref), false, "local-first");
|
|
2341
|
-
store = context.store;
|
|
2342
|
-
contentCid = resolved.cid;
|
|
2343
|
-
reference = first;
|
|
2344
|
-
const bundle = await openBundle(CID.parse(contentCid), {
|
|
2345
|
-
resolveCid: (key) => context.store.block.get(key.toString()),
|
|
2346
|
-
});
|
|
2347
|
-
schemaCid = bundle.schemaKey;
|
|
2348
|
-
resolvedFrom = "uri";
|
|
2349
|
-
association = await swarmTypeSkill(context, targetSwarm, schemaCid, {
|
|
2350
|
-
mode: "local-first",
|
|
2351
|
-
...refreshOption,
|
|
2352
|
-
});
|
|
2574
|
+
else {
|
|
2575
|
+
const preview = (await client.host.syncSkills({
|
|
2576
|
+
...syncParams,
|
|
2577
|
+
dryRun: true,
|
|
2578
|
+
yes: false,
|
|
2579
|
+
}, { ndjson: true }));
|
|
2580
|
+
if (!preview.ok) {
|
|
2581
|
+
result = preview;
|
|
2582
|
+
}
|
|
2583
|
+
else {
|
|
2584
|
+
const selected = preview.items.filter((skill) => !parsed.positional.length ||
|
|
2585
|
+
parsed.positional.includes(skill.name) ||
|
|
2586
|
+
parsed.positional.includes(skill.identity));
|
|
2587
|
+
const hasChanges = selected.some((skill) => skill.agents.some((agent) => agent.status !== "current"));
|
|
2588
|
+
if (!selected.length) {
|
|
2589
|
+
result = { ...preview, dryRun: false };
|
|
2353
2590
|
}
|
|
2354
2591
|
else {
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
const session = `skills-show:${randomUUID()}`;
|
|
2359
|
-
const owner = await Ownership.create(state, store, `skills-show:${randomUUID()}`, session);
|
|
2360
|
-
try {
|
|
2361
|
-
const root = await snapshotLocalBundle(localInput, owner, session, {
|
|
2362
|
-
diagnostic: (text) => {
|
|
2363
|
-
io.err(text);
|
|
2364
|
-
},
|
|
2365
|
-
});
|
|
2366
|
-
contentCid = await artifactValue(store, root);
|
|
2367
|
-
const bundle = await openBundle(CID.parse(contentCid), {
|
|
2368
|
-
resolveCid: (key) => store.block.get(key.toString()),
|
|
2369
|
-
});
|
|
2370
|
-
schemaCid = bundle.schemaKey;
|
|
2371
|
-
resolvedFrom = "local";
|
|
2372
|
-
association = await swarmTypeSkill(context, targetSwarm, schemaCid, {
|
|
2373
|
-
mode: "local-first",
|
|
2374
|
-
...refreshOption,
|
|
2375
|
-
});
|
|
2376
|
-
}
|
|
2377
|
-
finally {
|
|
2378
|
-
await owner.release();
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
else {
|
|
2382
|
-
const resolved = state.resolve(schemaAlias(first));
|
|
2383
|
-
const parsedCid = CID.parse(resolved);
|
|
2384
|
-
const isSchemaCid = parsedCid.code === 0x71 && parsedCid.multihash.code === 0x12;
|
|
2385
|
-
schemaCid = resolved;
|
|
2386
|
-
resolvedFrom = "schema";
|
|
2387
|
-
if (isSchemaCid) {
|
|
2388
|
-
association = await swarmTypeSkill(context, targetSwarm, resolved, {
|
|
2389
|
-
mode: "local-first",
|
|
2390
|
-
...refreshOption,
|
|
2391
|
-
});
|
|
2392
|
-
}
|
|
2393
|
-
else {
|
|
2394
|
-
const refResolved = await resolveReference(context, resolved, targetSwarm, (ref) => state.resolve(ref), false, "local-first");
|
|
2395
|
-
store = context.store;
|
|
2396
|
-
const bundle = await openBundle(CID.parse(refResolved.cid), {
|
|
2397
|
-
resolveCid: (key) => context.store.block.get(key.toString()),
|
|
2398
|
-
});
|
|
2399
|
-
schemaCid = bundle.schemaKey;
|
|
2400
|
-
contentCid = refResolved.cid;
|
|
2401
|
-
resolvedFrom = "content";
|
|
2402
|
-
association = await swarmTypeSkill(context, targetSwarm, schemaCid, {
|
|
2403
|
-
mode: "local-first",
|
|
2404
|
-
...refreshOption,
|
|
2405
|
-
});
|
|
2406
|
-
}
|
|
2592
|
+
if (hasChanges &&
|
|
2593
|
+
!(await io.confirm(`Authorize ${preview.installer} and the changes above?`))) {
|
|
2594
|
+
throw new HostError("Skill sync requires --yes or interactive consent. Use --override-existing to authorize replacing existing Skills; source and link conflicts remain protected.");
|
|
2407
2595
|
}
|
|
2596
|
+
result = (await client.host.syncSkills({
|
|
2597
|
+
...syncParams,
|
|
2598
|
+
dryRun: false,
|
|
2599
|
+
yes: true,
|
|
2600
|
+
quietPreview: true,
|
|
2601
|
+
}, { ndjson: true }));
|
|
2408
2602
|
}
|
|
2409
|
-
store = context.store;
|
|
2410
|
-
if (!association)
|
|
2411
|
-
throw new HostError(`No Skill associated with Schema ${schemaCid} in Swarm ${targetSwarm}. Associate one with: ipab skills set SKILL --type ${schemaCid}`, 1, "SKILL_NOT_FOUND", "state");
|
|
2412
|
-
const payload = {
|
|
2413
|
-
swarm: targetSwarm,
|
|
2414
|
-
schemaCid,
|
|
2415
|
-
resolvedFrom,
|
|
2416
|
-
...(contentCid ? { contentCid } : {}),
|
|
2417
|
-
...(reference ? { reference } : {}),
|
|
2418
|
-
name: association.name,
|
|
2419
|
-
cid: association.cid,
|
|
2420
|
-
identity: association.identity,
|
|
2421
|
-
description: association.description,
|
|
2422
|
-
};
|
|
2423
|
-
const lines = [
|
|
2424
|
-
`Swarm: ${targetSwarm}`,
|
|
2425
|
-
`Schema: ${schemaCid}`,
|
|
2426
|
-
...(contentCid ? [`Content CID: ${contentCid}`] : []),
|
|
2427
|
-
`Skill: ${association.identity}`,
|
|
2428
|
-
`Skill CID: ${association.cid}`,
|
|
2429
|
-
`Path: ${association.name}`,
|
|
2430
|
-
`Description: ${association.description}`,
|
|
2431
|
-
];
|
|
2432
|
-
emit(payload, lines.join("\n"));
|
|
2433
|
-
break;
|
|
2434
|
-
}
|
|
2435
|
-
if (parsed.path === "skills set") {
|
|
2436
|
-
const targetSwarm = requireSwarm();
|
|
2437
|
-
const types = (parsed.types ?? []).map((schema) => state.resolve(schemaAlias(schema), true));
|
|
2438
|
-
const localSkill = !parseNameReference(first)
|
|
2439
|
-
? await resolveLocalBundleInput(first)
|
|
2440
|
-
: undefined;
|
|
2441
|
-
let skillOwner;
|
|
2442
|
-
try {
|
|
2443
|
-
let skillCid;
|
|
2444
|
-
if (localSkill) {
|
|
2445
|
-
const session = `skills-set:${randomUUID()}`;
|
|
2446
|
-
skillOwner = await Ownership.create(state, store, `skills-set:${randomUUID()}`, session);
|
|
2447
|
-
skillCid = await snapshotLocalBundle(localSkill, skillOwner, session, {
|
|
2448
|
-
diagnostic: (text) => {
|
|
2449
|
-
io.err(text);
|
|
2450
|
-
},
|
|
2451
|
-
});
|
|
2452
|
-
}
|
|
2453
|
-
else if (parseNameReference(first)) {
|
|
2454
|
-
skillCid = (await resolveReference(context, first, targetSwarm, (ref) => state.resolve(ref), false)).cid;
|
|
2455
|
-
store = context.store;
|
|
2456
|
-
}
|
|
2457
|
-
else {
|
|
2458
|
-
skillCid = state.resolve(first);
|
|
2459
|
-
}
|
|
2460
|
-
const result = await setSwarmSkill(context, targetSwarm, {
|
|
2461
|
-
skillCid,
|
|
2462
|
-
global: Boolean(parsed.options.global),
|
|
2463
|
-
types,
|
|
2464
|
-
replace: Boolean(parsed.options.replace),
|
|
2465
|
-
});
|
|
2466
|
-
store = context.store;
|
|
2467
|
-
const text = result.changed
|
|
2468
|
-
? [
|
|
2469
|
-
`Skill: ${result.identity} (${result.cid})`,
|
|
2470
|
-
`HEAD: ${result.headCid}`,
|
|
2471
|
-
...result.targets.map((target) => {
|
|
2472
|
-
const status = !target.changed
|
|
2473
|
-
? "unchanged"
|
|
2474
|
-
: target.previousCid
|
|
2475
|
-
? "updated"
|
|
2476
|
-
: "created";
|
|
2477
|
-
return target.scope === "global"
|
|
2478
|
-
? ` global -> ${target.name} (${status})`
|
|
2479
|
-
: ` type ${target.schemaCid} -> ${target.name} (${status})`;
|
|
2480
|
-
}),
|
|
2481
|
-
].join("\n")
|
|
2482
|
-
: `Unchanged: ${result.identity} (${result.cid}) (HEAD ${result.headCid})`;
|
|
2483
|
-
emit(result, text);
|
|
2484
|
-
}
|
|
2485
|
-
finally {
|
|
2486
|
-
await skillOwner?.release();
|
|
2487
|
-
}
|
|
2488
|
-
break;
|
|
2489
|
-
}
|
|
2490
|
-
if (parsed.path === "skills remove") {
|
|
2491
|
-
const targetSwarm = requireSwarm();
|
|
2492
|
-
const types = (parsed.types ?? []).map((schema) => state.resolve(schemaAlias(schema), true));
|
|
2493
|
-
const globalName = typeof parsed.options.global === "string"
|
|
2494
|
-
? parsed.options.global
|
|
2495
|
-
: undefined;
|
|
2496
|
-
const result = await removeSwarmSkill(context, targetSwarm, {
|
|
2497
|
-
...(globalName !== undefined ? { globalName } : {}),
|
|
2498
|
-
types,
|
|
2499
|
-
});
|
|
2500
|
-
store = context.store;
|
|
2501
|
-
const lines = [
|
|
2502
|
-
`Removed ${result.removed.length} Skill association(s) (HEAD ${result.headCid}):`,
|
|
2503
|
-
...result.removed.map((entry) => entry.scope === "global"
|
|
2504
|
-
? ` global ${entry.name} (was ${entry.removedCid})`
|
|
2505
|
-
: ` type ${entry.schemaCid} ${entry.name} (was ${entry.removedCid})`),
|
|
2506
|
-
];
|
|
2507
|
-
emit(result, lines.join("\n"));
|
|
2508
|
-
break;
|
|
2509
|
-
}
|
|
2510
|
-
if (parsed.path === "skills list") {
|
|
2511
|
-
const targetSwarm = requireSwarm();
|
|
2512
|
-
const managed = await manageSkills(context, targetSwarm, {
|
|
2513
|
-
sync: false,
|
|
2514
|
-
names: parsed.positional,
|
|
2515
|
-
agents: parsed.agents ?? [],
|
|
2516
|
-
overrideExisting: false,
|
|
2517
|
-
dryRun: false,
|
|
2518
|
-
yes: false,
|
|
2519
|
-
tty: io.tty,
|
|
2520
|
-
confirm: (text) => io.confirm(text),
|
|
2521
|
-
preview: (text) => {
|
|
2522
|
-
io.err(text);
|
|
2523
|
-
},
|
|
2524
|
-
});
|
|
2525
|
-
const typeSkills = await swarmTypeSkills(context, targetSwarm, {
|
|
2526
|
-
mode: "local-first",
|
|
2527
|
-
...refreshOption,
|
|
2528
|
-
});
|
|
2529
|
-
const result = {
|
|
2530
|
-
swarm: managed.swarm,
|
|
2531
|
-
installer: managed.installer,
|
|
2532
|
-
agents: managed.agents,
|
|
2533
|
-
dryRun: managed.dryRun,
|
|
2534
|
-
items: managed.items,
|
|
2535
|
-
typeSkills,
|
|
2536
|
-
orphaned: managed.orphaned,
|
|
2537
|
-
results: managed.results,
|
|
2538
|
-
ok: managed.ok,
|
|
2539
|
-
};
|
|
2540
|
-
store = context.store;
|
|
2541
|
-
const globalLines = [
|
|
2542
|
-
table(["NAME", "PAYLOAD CID", "INSTALL NAME", "STATUS"], result.items.map((skill) => [
|
|
2543
|
-
skill.name,
|
|
2544
|
-
skill.cid,
|
|
2545
|
-
skill.identity,
|
|
2546
|
-
skill.status,
|
|
2547
|
-
]), "No Global Skills."),
|
|
2548
|
-
...result.items.flatMap((skill) => skill.problems),
|
|
2549
|
-
...result.orphaned.map((skill) => `Source removed: ${skill.name} ${skill.cid} (${skill.path}); installation retained.`),
|
|
2550
|
-
];
|
|
2551
|
-
const typeLines = [
|
|
2552
|
-
"Type Skills:",
|
|
2553
|
-
table(["TYPE CID", "SKILL NAME", "SKILL CID"], result.typeSkills.map((entry) => [
|
|
2554
|
-
entry.schemaCid,
|
|
2555
|
-
entry.identity,
|
|
2556
|
-
entry.cid,
|
|
2557
|
-
]), "No Type Skills."),
|
|
2558
|
-
];
|
|
2559
|
-
emit(result, [...globalLines, "", ...typeLines].join("\n"));
|
|
2560
|
-
if (!result.ok)
|
|
2561
|
-
return 1;
|
|
2562
|
-
break;
|
|
2563
2603
|
}
|
|
2564
|
-
const result = await manageSkills(context, requireSwarm(), {
|
|
2565
|
-
sync: true,
|
|
2566
|
-
names: parsed.positional,
|
|
2567
|
-
agents: parsed.agents ?? [],
|
|
2568
|
-
overrideExisting: Boolean(parsed.options["override-existing"]),
|
|
2569
|
-
dryRun: Boolean(parsed.options["dry-run"]),
|
|
2570
|
-
yes: Boolean(parsed.options.yes),
|
|
2571
|
-
tty: io.tty,
|
|
2572
|
-
confirm: (text) => io.confirm(text),
|
|
2573
|
-
preview: (text) => {
|
|
2574
|
-
io.err(text);
|
|
2575
|
-
},
|
|
2576
|
-
});
|
|
2577
|
-
store = context.store;
|
|
2578
|
-
emit(result, [
|
|
2579
|
-
table(["NAME", "PAYLOAD CID", "INSTALL NAME", "STATUS"], result.items.map((skill) => [
|
|
2580
|
-
skill.name,
|
|
2581
|
-
skill.cid,
|
|
2582
|
-
skill.identity,
|
|
2583
|
-
skill.status,
|
|
2584
|
-
]), "No Skills."),
|
|
2585
|
-
...result.items.flatMap((skill) => skill.problems),
|
|
2586
|
-
...result.orphaned.map((skill) => `Source removed: ${skill.name} ${skill.cid} (${skill.path}); installation retained.`),
|
|
2587
|
-
...result.results.map((entry) => `${entry.name} / ${entry.agent}: ${entry.status}${entry.error ? `: ${entry.error}` : ""}`),
|
|
2588
|
-
].join("\n"));
|
|
2589
|
-
if (!result.ok)
|
|
2590
|
-
return 1;
|
|
2591
|
-
break;
|
|
2592
|
-
}
|
|
2593
|
-
if (parsed.path === "pin") {
|
|
2594
|
-
io.err("Fetching, verifying and retaining content...");
|
|
2595
|
-
const result = await pinNameSubscription(context, first, selectedSwarm);
|
|
2596
|
-
store = context.store;
|
|
2597
|
-
emit(result, `${result.reference} → ${result.cid}\nStatus: ${result.freshness}`);
|
|
2598
|
-
break;
|
|
2599
2604
|
}
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
}
|
|
2605
|
+
emit(result, [
|
|
2606
|
+
table(["NAME", "PAYLOAD CID", "INSTALL NAME", "STATUS"], result.items.map((skill) => [
|
|
2607
|
+
skill.name,
|
|
2608
|
+
skill.cid,
|
|
2609
|
+
skill.identity,
|
|
2610
|
+
skill.status,
|
|
2611
|
+
]), "No Skills."),
|
|
2612
|
+
...result.items.flatMap((skill) => skill.problems),
|
|
2613
|
+
...result.orphaned.map((skill) => `Source removed: ${skill.name} ${skill.cid} (${skill.path}); installation retained.`),
|
|
2614
|
+
...result.results.map((entry) => `${entry.name} / ${entry.agent}: ${entry.status}${entry.error ? `: ${entry.error}` : ""}`),
|
|
2615
|
+
].join("\n"));
|
|
2616
|
+
if (!result.ok)
|
|
2617
|
+
return 1;
|
|
2618
|
+
break;
|
|
2619
|
+
}
|
|
2620
|
+
case "pin": {
|
|
2621
|
+
io.err("Fetching, verifying and retaining content...");
|
|
2622
|
+
const result = await client.store.addPin({
|
|
2623
|
+
ref: first,
|
|
2624
|
+
swarm: selectedSwarm,
|
|
2625
|
+
refresh: explicitRefresh,
|
|
2626
|
+
}, { ndjson: true });
|
|
2627
|
+
emit(result, `${result.reference} → ${result.cid}\nStatus: ${result.freshness}`);
|
|
2628
|
+
break;
|
|
2629
|
+
}
|
|
2630
|
+
case "swarm members": {
|
|
2631
|
+
const result = (await client.swarms.members({
|
|
2632
|
+
swarm: requireSwarm(),
|
|
2633
|
+
refresh: Boolean(parsed.options.refresh || parsed.options.force),
|
|
2634
|
+
}, { ndjson: true }));
|
|
2635
|
+
if (result.mode === "local") {
|
|
2610
2636
|
emit(result, [
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
member.name,
|
|
2615
|
-
member.description,
|
|
2616
|
-
member.role,
|
|
2617
|
-
member.pivot ? (member.localStatus ?? "candidate") : "-",
|
|
2618
|
-
member.publicKey,
|
|
2619
|
-
]), "No members."),
|
|
2637
|
+
"Swarm: local (Built-in single-machine Swarm)",
|
|
2638
|
+
"Mode: local",
|
|
2639
|
+
"Members: local user only (single-machine; no remote collaborators or HOME identity required)",
|
|
2620
2640
|
].join("\n"));
|
|
2621
|
-
if (result.local.error)
|
|
2622
|
-
io.err(`Local Pivot observations (${result.local.status}): ${printable(result.local.error)}`);
|
|
2623
|
-
break;
|
|
2624
|
-
}
|
|
2625
|
-
if (parsed.path === "swarm export") {
|
|
2626
|
-
const member = await exportRequest(context, requireSwarm(), String(parsed.options.output ?? ""));
|
|
2627
|
-
emit({ member }, member);
|
|
2628
|
-
break;
|
|
2629
|
-
}
|
|
2630
|
-
if (parsed.path === "swarm pivot grant") {
|
|
2631
|
-
const url = requireSwarm();
|
|
2632
|
-
if (!parsed.options.yes)
|
|
2633
|
-
syntax("Granting Pivot HEAD receipt authority requires --yes; revoking it requires swarm exclude.");
|
|
2634
|
-
const result = await grantPivotAuthority(context, url, first);
|
|
2635
|
-
store = context.store;
|
|
2636
|
-
emit(result, `Granted Pivot HEAD authority to ${result.member} on ${result.configUrl} (HEAD ${result.headId}). Revoking Pivot HEAD authority requires swarm exclude.`);
|
|
2637
|
-
break;
|
|
2638
|
-
}
|
|
2639
|
-
if (["swarm exclude", "swarm resume", "swarm profile"].includes(parsed.path)) {
|
|
2640
|
-
const url = requireSwarm();
|
|
2641
|
-
if (parsed.path === "swarm exclude") {
|
|
2642
|
-
if (!parsed.options.yes)
|
|
2643
|
-
syntax("Member removal is irreversible; --yes required.");
|
|
2644
|
-
await removeMember(context, url, first);
|
|
2645
|
-
}
|
|
2646
|
-
else if (parsed.path === "swarm resume")
|
|
2647
|
-
await resumeRemoval(context, url);
|
|
2648
|
-
else {
|
|
2649
|
-
const profile = await updateProfile(context, url, {
|
|
2650
|
-
...(typeof parsed.options.address === "string"
|
|
2651
|
-
? { addresses: [parsed.options.address] }
|
|
2652
|
-
: {}),
|
|
2653
|
-
...(typeof parsed.options.pivot === "string"
|
|
2654
|
-
? {
|
|
2655
|
-
pivot: Boolean(parseValue("swarm.pivot", parsed.options.pivot, true)),
|
|
2656
|
-
}
|
|
2657
|
-
: {}),
|
|
2658
|
-
});
|
|
2659
|
-
emit(profile, JSON.stringify(profile));
|
|
2660
|
-
store = context.store;
|
|
2661
|
-
break;
|
|
2662
|
-
}
|
|
2663
|
-
store = context.store;
|
|
2664
|
-
emit({ url, completed: true }, `Organization switch complete: ${url}`);
|
|
2665
|
-
break;
|
|
2666
|
-
}
|
|
2667
|
-
if (parsed.path === "swarm update") {
|
|
2668
|
-
const cid = requireSwarm();
|
|
2669
|
-
const result = await updateSwarm(context, cid, {
|
|
2670
|
-
...(typeof parsed.options.name === "string"
|
|
2671
|
-
? { name: parsed.options.name }
|
|
2672
|
-
: {}),
|
|
2673
|
-
...(typeof parsed.options.description === "string"
|
|
2674
|
-
? { description: parsed.options.description }
|
|
2675
|
-
: {}),
|
|
2676
|
-
});
|
|
2677
|
-
emit(result, `Swarm: ${result.configUrl}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD ID: ${result.headId}\nConfig content CID: ${result.valueCid}`);
|
|
2678
|
-
break;
|
|
2679
|
-
}
|
|
2680
|
-
if (parsed.path === "search") {
|
|
2681
|
-
const registrations = state.allSwarms();
|
|
2682
|
-
const scope = parsed.options.all
|
|
2683
|
-
? registrations
|
|
2684
|
-
: [
|
|
2685
|
-
{
|
|
2686
|
-
cid: requireSwarm(),
|
|
2687
|
-
alias: registrations.find((entry) => entry.cid === selectedSwarm)
|
|
2688
|
-
?.alias ?? null,
|
|
2689
|
-
},
|
|
2690
|
-
];
|
|
2691
|
-
const searchOptions = {};
|
|
2692
|
-
if (typeof parsed.options.prefix === "string")
|
|
2693
|
-
searchOptions.prefix = parsed.options.prefix;
|
|
2694
|
-
if (typeof parsed.options.kind === "string")
|
|
2695
|
-
searchOptions.kind = parsed.options.kind;
|
|
2696
|
-
if (typeof parsed.options.schema === "string")
|
|
2697
|
-
searchOptions.schemaCid = parsed.options.schema;
|
|
2698
|
-
if (typeof parsed.options.limit === "string")
|
|
2699
|
-
searchOptions.limit = /^\d+$/.test(parsed.options.limit)
|
|
2700
|
-
? Number(parsed.options.limit)
|
|
2701
|
-
: Number.NaN;
|
|
2702
|
-
if (typeof parsed.options.offset === "string")
|
|
2703
|
-
searchOptions.offset = /^\d+$/.test(parsed.options.offset)
|
|
2704
|
-
? Number(parsed.options.offset)
|
|
2705
|
-
: Number.NaN;
|
|
2706
|
-
const result = Object.keys(searchOptions).length
|
|
2707
|
-
? await searchNames(context, first, scope, searchOptions)
|
|
2708
|
-
: await searchNames(context, first, scope);
|
|
2709
|
-
emit(result, formatSearchResults(result.matches));
|
|
2710
2641
|
break;
|
|
2711
2642
|
}
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2643
|
+
emit(result, [
|
|
2644
|
+
`Directory: ${result.cache.source} (${result.cache.freshness}), observed ${result.cache.updatedAt}`,
|
|
2645
|
+
`Daemon: ${result.local.status}, observed ${result.local.updatedAt ?? "unknown"}; control-plane verified ${result.local.verifiedAt ?? "unknown"}`,
|
|
2646
|
+
table(["NAME", "DESCRIPTION", "ROLE", "PIVOT", "PUBLIC KEY"], result.members.map((member) => [
|
|
2647
|
+
member.name,
|
|
2648
|
+
member.description,
|
|
2649
|
+
member.role,
|
|
2650
|
+
member.pivot ? (member.localStatus ?? "candidate") : "-",
|
|
2651
|
+
member.publicKey,
|
|
2652
|
+
]), "No members."),
|
|
2653
|
+
].join("\n"));
|
|
2654
|
+
if (result.local.error)
|
|
2655
|
+
io.err(`Local Pivot observations (${result.local.status}): ${printable(result.local.error)}`);
|
|
2656
|
+
break;
|
|
2657
|
+
}
|
|
2658
|
+
case "swarm export": {
|
|
2659
|
+
const output = typeof parsed.options.output === "string"
|
|
2660
|
+
? resolve(parsed.options.output)
|
|
2661
|
+
: "";
|
|
2662
|
+
const result = (await client.swarms.governance("export", { swarm: requireSwarm(), output }, { ndjson: true }));
|
|
2663
|
+
emit({ member: result.member }, result.member);
|
|
2664
|
+
break;
|
|
2665
|
+
}
|
|
2666
|
+
case "swarm pivot grant": {
|
|
2667
|
+
const url = requireSwarm();
|
|
2668
|
+
if (!parsed.options.yes)
|
|
2669
|
+
syntax("Granting Pivot HEAD receipt authority requires --yes; revoking it requires swarm exclude.");
|
|
2670
|
+
const result = (await client.swarms.governance("pivot-grant", { swarm: url, member: first }, { ndjson: true }));
|
|
2671
|
+
emit(result, `Granted Pivot HEAD authority to ${result.member} on ${result.configUrl} (HEAD ${result.headId}). Revoking Pivot HEAD authority requires swarm exclude.`);
|
|
2672
|
+
break;
|
|
2673
|
+
}
|
|
2674
|
+
case "swarm exclude": {
|
|
2675
|
+
const url = requireSwarm();
|
|
2676
|
+
if (!parsed.options.yes)
|
|
2677
|
+
syntax("Member removal is irreversible; --yes required.");
|
|
2678
|
+
await client.swarms.governance("exclude", { swarm: url, member: first }, { ndjson: true });
|
|
2679
|
+
emit({ url, completed: true }, `Organization switch complete: ${url}`);
|
|
2680
|
+
break;
|
|
2681
|
+
}
|
|
2682
|
+
case "swarm resume": {
|
|
2683
|
+
const url = requireSwarm();
|
|
2684
|
+
await client.swarms.governance("resume", { swarm: url }, { ndjson: true });
|
|
2685
|
+
emit({ url, completed: true }, `Organization switch complete: ${url}`);
|
|
2686
|
+
break;
|
|
2687
|
+
}
|
|
2688
|
+
case "swarm profile": {
|
|
2689
|
+
const url = requireSwarm();
|
|
2690
|
+
const profile = await client.swarms.governance("profile", {
|
|
2691
|
+
swarm: url,
|
|
2692
|
+
...(typeof parsed.options.address === "string"
|
|
2693
|
+
? { addresses: [parsed.options.address] }
|
|
2694
|
+
: {}),
|
|
2695
|
+
...(typeof parsed.options.pivot === "string"
|
|
2696
|
+
? {
|
|
2697
|
+
pivot: Boolean(parseValue("swarm.pivot", parsed.options.pivot, true)),
|
|
2698
|
+
}
|
|
2699
|
+
: {}),
|
|
2700
|
+
}, { ndjson: true });
|
|
2701
|
+
emit(profile, JSON.stringify(profile));
|
|
2702
|
+
break;
|
|
2703
|
+
}
|
|
2704
|
+
case "swarm update": {
|
|
2705
|
+
const cid = requireSwarm();
|
|
2706
|
+
const result = (await client.swarms.update({
|
|
2707
|
+
swarm: cid,
|
|
2708
|
+
...(typeof parsed.options.name === "string"
|
|
2709
|
+
? { name: parsed.options.name }
|
|
2710
|
+
: {}),
|
|
2711
|
+
...(typeof parsed.options.description === "string"
|
|
2712
|
+
? { description: parsed.options.description }
|
|
2713
|
+
: {}),
|
|
2714
|
+
}, { ndjson: true }));
|
|
2715
|
+
emit(result, `Swarm: ${result.configUrl}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD ID: ${result.headId}\nConfig content CID: ${result.valueCid}`);
|
|
2716
|
+
break;
|
|
2717
|
+
}
|
|
2718
|
+
case "search": {
|
|
2719
|
+
const result = (await client.swarms.search({
|
|
2720
|
+
...(parsed.options.all
|
|
2721
|
+
? { swarms: registeredSwarms.map((entry) => entry.cid) }
|
|
2722
|
+
: { swarm: requireSwarm() }),
|
|
2723
|
+
q: first,
|
|
2724
|
+
...(typeof parsed.options.prefix === "string"
|
|
2725
|
+
? { prefix: parsed.options.prefix }
|
|
2726
|
+
: {}),
|
|
2727
|
+
...(typeof parsed.options.kind === "string"
|
|
2728
|
+
? {
|
|
2729
|
+
kind: parsed.options.kind,
|
|
2730
|
+
}
|
|
2731
|
+
: {}),
|
|
2732
|
+
...(typeof parsed.options.schema === "string"
|
|
2733
|
+
? { schemaCid: parsed.options.schema }
|
|
2734
|
+
: {}),
|
|
2735
|
+
...(typeof parsed.options.limit === "string"
|
|
2736
|
+
? { limit: parsed.options.limit }
|
|
2737
|
+
: {}),
|
|
2738
|
+
...(typeof parsed.options.offset === "string"
|
|
2739
|
+
? { offset: parsed.options.offset }
|
|
2740
|
+
: {}),
|
|
2741
|
+
refresh: explicitRefresh,
|
|
2742
|
+
}, { ndjson: true }));
|
|
2743
|
+
emit(result, formatSearchResults(result.matches));
|
|
2744
|
+
break;
|
|
2745
|
+
}
|
|
2746
|
+
case "swarm status": {
|
|
2747
|
+
const { keyId } = await import("@ipab/bundle/pointer/crypto");
|
|
2748
|
+
const cid = requireSwarm();
|
|
2749
|
+
const status = (await client.swarms.status({
|
|
2750
|
+
swarm: cid,
|
|
2751
|
+
refresh: Boolean(parsed.options.refresh || parsed.options.force),
|
|
2752
|
+
}, { ndjson: true }));
|
|
2753
|
+
if (status.mode === "local") {
|
|
2746
2754
|
emit({
|
|
2755
|
+
mode: "local",
|
|
2747
2756
|
configUrl: cid,
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
epoch: config.epoch,
|
|
2751
|
-
scopeId: config.scopeId,
|
|
2752
|
-
headId: config.headId,
|
|
2753
|
-
cache,
|
|
2754
|
-
state: contentState,
|
|
2755
|
-
networking,
|
|
2756
|
-
root: head.root,
|
|
2757
|
-
valueCid: head.cid,
|
|
2758
|
-
lastWriter,
|
|
2757
|
+
root: status.head.root,
|
|
2758
|
+
valueCid: status.head.cid,
|
|
2759
2759
|
properties: {
|
|
2760
|
-
name: config.name,
|
|
2761
|
-
description: config.description,
|
|
2760
|
+
name: status.config.name,
|
|
2761
|
+
description: status.config.description,
|
|
2762
2762
|
},
|
|
2763
|
+
local: status.local,
|
|
2763
2764
|
}, [
|
|
2764
2765
|
"Swarm",
|
|
2765
|
-
|
|
2766
|
-
` Name: ${printable(config.name)}`,
|
|
2767
|
-
` Description: ${
|
|
2766
|
+
" Mode: local (built-in single-machine Swarm)",
|
|
2767
|
+
` Name: ${printable(status.config.name)}`,
|
|
2768
|
+
` Description: ${printable(status.config.description)}`,
|
|
2768
2769
|
" Config URL:",
|
|
2769
2770
|
` ${cid}`,
|
|
2770
2771
|
"",
|
|
2771
|
-
"Identity",
|
|
2772
|
-
" Owner fingerprint:",
|
|
2773
|
-
` ${fingerprint}`,
|
|
2774
|
-
"",
|
|
2775
2772
|
"Content",
|
|
2776
2773
|
" HEAD (publication root):",
|
|
2777
|
-
` ${head.root}`,
|
|
2774
|
+
` ${status.head.root}`,
|
|
2778
2775
|
" Content CID (HEAD value):",
|
|
2779
|
-
` ${head.cid}`,
|
|
2780
|
-
|
|
2781
|
-
? [
|
|
2782
|
-
` Last HEAD writer: ${lastWriter.name ? printable(lastWriter.name) : "(profile name unavailable)"}`,
|
|
2783
|
-
` Public key: ${lastWriter.subject}`,
|
|
2784
|
-
` PeerID: ${lastWriter.peerId ?? "unknown"}`,
|
|
2785
|
-
` Updated: ${lastWriter.updatedAt} (service time)`,
|
|
2786
|
-
" Last writer is not a confirmed content holder or the only copy.",
|
|
2787
|
-
]
|
|
2788
|
-
: [
|
|
2789
|
-
" Last HEAD writer/time: unknown (legacy record or service without update metadata).",
|
|
2790
|
-
]),
|
|
2791
|
-
` State: ${contentState.status}. ${contentState.error}`,
|
|
2792
|
-
"",
|
|
2793
|
-
"Local networking",
|
|
2794
|
-
` Daemon observations: ${networking.daemon.status}`,
|
|
2795
|
-
` Updated: ${networking.daemon.updatedAt ?? "unknown"}`,
|
|
2796
|
-
` Control-plane verified: ${networking.daemon.verifiedAt ?? "unknown"}`,
|
|
2797
|
-
...(networking.daemon.error
|
|
2798
|
-
? [` Observation error: ${printable(networking.daemon.error)}`]
|
|
2799
|
-
: []),
|
|
2800
|
-
` Connections observed: ${networking.connections.observedAt ?? "unknown"} (${networking.connections.freshness})`,
|
|
2801
|
-
...(networking.connections.error
|
|
2802
|
-
? [
|
|
2803
|
-
` Connection error: ${printable(networking.connections.error)}`,
|
|
2804
|
-
]
|
|
2805
|
-
: []),
|
|
2806
|
-
table([
|
|
2807
|
-
"PIVOT PEER ID",
|
|
2808
|
-
"LOCAL",
|
|
2809
|
-
"PROBE",
|
|
2810
|
-
"PROBED AT",
|
|
2811
|
-
"FAILURES",
|
|
2812
|
-
"RETRY AT",
|
|
2813
|
-
"CONNECTION",
|
|
2814
|
-
"READINESS",
|
|
2815
|
-
], networking.pivots.map((pivot) => [
|
|
2816
|
-
pivot.peerId,
|
|
2817
|
-
pivot.localStatus ?? "unknown",
|
|
2818
|
-
`${pivot.probe.result} (${pivot.probe.freshness})`,
|
|
2819
|
-
pivot.probe.at ?? "-",
|
|
2820
|
-
pivot.failures === null ? "-" : String(pivot.failures),
|
|
2821
|
-
pivot.retryAt ?? "-",
|
|
2822
|
-
pivot.connection.status,
|
|
2823
|
-
pivot.readiness.status,
|
|
2824
|
-
]), "No declared Pivots."),
|
|
2825
|
-
...networking.pivots.flatMap((pivot) => pivot.probe.error
|
|
2826
|
-
? [
|
|
2827
|
-
` ${pivot.peerId} probe error: ${printable(pivot.probe.error)}`,
|
|
2828
|
-
]
|
|
2829
|
-
: []),
|
|
2830
|
-
...(networking.connections.error
|
|
2831
|
-
? []
|
|
2832
|
-
: [
|
|
2833
|
-
table(["CONNECTED PEER ID", "TRANSPORT", "ADDRESS"], networking.connections.peers.map((peer) => [
|
|
2834
|
-
peer.peerId,
|
|
2835
|
-
peer.transport,
|
|
2836
|
-
peer.address,
|
|
2837
|
-
]), "No observed peer connections."),
|
|
2838
|
-
]),
|
|
2839
|
-
" Selected is configuration, not connection success. Relay connectivity does not guarantee content availability.",
|
|
2776
|
+
` ${status.head.cid}`,
|
|
2777
|
+
` Names: ${status.local.names} (Templates: ${status.local.templates}, Skills: ${status.local.skills} [global: ${status.local.globalSkills}, types: ${status.local.typeSkills}], Registrations: ${status.local.registrations})`,
|
|
2840
2778
|
].join("\n"));
|
|
2841
2779
|
break;
|
|
2842
2780
|
}
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
}
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
: {}
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2781
|
+
const { head, config, networking, cache, lastWriter, state: contentState, } = status;
|
|
2782
|
+
const fingerprint = await keyId(config.owner);
|
|
2783
|
+
emit({
|
|
2784
|
+
configUrl: cid,
|
|
2785
|
+
owner: config.owner,
|
|
2786
|
+
ownerFingerprint: fingerprint,
|
|
2787
|
+
epoch: config.epoch,
|
|
2788
|
+
scopeId: config.scopeId,
|
|
2789
|
+
headId: config.headId,
|
|
2790
|
+
cache,
|
|
2791
|
+
state: contentState,
|
|
2792
|
+
networking,
|
|
2793
|
+
root: head.root,
|
|
2794
|
+
valueCid: head.cid,
|
|
2795
|
+
lastWriter,
|
|
2796
|
+
properties: {
|
|
2797
|
+
name: config.name,
|
|
2798
|
+
description: config.description,
|
|
2799
|
+
},
|
|
2800
|
+
}, [
|
|
2801
|
+
"Swarm",
|
|
2802
|
+
` Directory: ${cache.source} (${cache.freshness}), observed ${cache.updatedAt}`,
|
|
2803
|
+
` Name: ${printable(config.name)}`,
|
|
2804
|
+
` Description: ${config.description ? printable(config.description) : "(none)"}`,
|
|
2805
|
+
" Config URL:",
|
|
2806
|
+
` ${cid}`,
|
|
2807
|
+
"",
|
|
2808
|
+
"Identity",
|
|
2809
|
+
" Owner fingerprint:",
|
|
2810
|
+
` ${fingerprint}`,
|
|
2811
|
+
"",
|
|
2812
|
+
"Content",
|
|
2813
|
+
" HEAD (publication root):",
|
|
2814
|
+
` ${head.root}`,
|
|
2815
|
+
" Content CID (HEAD value):",
|
|
2816
|
+
` ${head.cid}`,
|
|
2817
|
+
...(lastWriter
|
|
2818
|
+
? [
|
|
2819
|
+
` Last HEAD writer: ${lastWriter.name ? printable(lastWriter.name) : "(profile name unavailable)"}`,
|
|
2820
|
+
` Public key: ${lastWriter.subject}`,
|
|
2821
|
+
` PeerID: ${lastWriter.peerId ?? "unknown"}`,
|
|
2822
|
+
` Updated: ${lastWriter.updatedAt} (service time)`,
|
|
2823
|
+
" Last writer is not a confirmed content holder or the only copy.",
|
|
2824
|
+
]
|
|
2825
|
+
: [
|
|
2826
|
+
" Last HEAD writer/time: unknown (legacy record or service without update metadata).",
|
|
2827
|
+
]),
|
|
2828
|
+
` State: ${contentState.status}. ${contentState.error}`,
|
|
2829
|
+
"",
|
|
2830
|
+
"Local networking",
|
|
2831
|
+
` Daemon observations: ${networking.daemon.status}`,
|
|
2832
|
+
` Updated: ${networking.daemon.updatedAt ?? "unknown"}`,
|
|
2833
|
+
` Control-plane verified: ${networking.daemon.verifiedAt ?? "unknown"}`,
|
|
2834
|
+
...(networking.daemon.error
|
|
2835
|
+
? [` Observation error: ${printable(networking.daemon.error)}`]
|
|
2836
|
+
: []),
|
|
2837
|
+
` Connections observed: ${networking.connections.observedAt ?? "unknown"} (${networking.connections.freshness})`,
|
|
2838
|
+
...(networking.connections.error
|
|
2839
|
+
? [
|
|
2840
|
+
` Connection error: ${printable(networking.connections.error)}`,
|
|
2841
|
+
]
|
|
2842
|
+
: []),
|
|
2843
|
+
table([
|
|
2844
|
+
"PIVOT PEER ID",
|
|
2845
|
+
"LOCAL",
|
|
2846
|
+
"PROBE",
|
|
2847
|
+
"PROBED AT",
|
|
2848
|
+
"FAILURES",
|
|
2849
|
+
"RETRY AT",
|
|
2850
|
+
"CONNECTION",
|
|
2851
|
+
"READINESS",
|
|
2852
|
+
], networking.pivots.map((pivot) => [
|
|
2853
|
+
pivot.peerId,
|
|
2854
|
+
pivot.localStatus ?? "unknown",
|
|
2855
|
+
`${pivot.probe.result} (${pivot.probe.freshness})`,
|
|
2856
|
+
pivot.probe.at ?? "-",
|
|
2857
|
+
pivot.failures === null ? "-" : String(pivot.failures),
|
|
2858
|
+
pivot.retryAt ?? "-",
|
|
2859
|
+
pivot.connection.status,
|
|
2860
|
+
pivot.readiness.status,
|
|
2861
|
+
]), "No declared Pivots."),
|
|
2862
|
+
...networking.pivots.flatMap((pivot) => pivot.probe.error
|
|
2863
|
+
? [
|
|
2864
|
+
` ${pivot.peerId} probe error: ${printable(pivot.probe.error)}`,
|
|
2865
|
+
]
|
|
2866
|
+
: []),
|
|
2867
|
+
...(networking.connections.error
|
|
2868
|
+
? []
|
|
2869
|
+
: [
|
|
2870
|
+
table(["CONNECTED PEER ID", "TRANSPORT", "ADDRESS"], networking.connections.peers.map((peer) => [
|
|
2871
|
+
peer.peerId,
|
|
2872
|
+
peer.transport,
|
|
2873
|
+
peer.address,
|
|
2874
|
+
]), "No observed peer connections."),
|
|
2875
|
+
]),
|
|
2876
|
+
" Selected is configuration, not connection success. Relay connectivity does not guarantee content availability.",
|
|
2877
|
+
].join("\n"));
|
|
2878
|
+
break;
|
|
2879
|
+
}
|
|
2880
|
+
case "get": {
|
|
2881
|
+
const destination = typeof parsed.options.output === "string"
|
|
2882
|
+
? resolve(parsed.options.output)
|
|
2883
|
+
: undefined;
|
|
2884
|
+
const result = (await client.store.export({
|
|
2885
|
+
mode: "get",
|
|
2886
|
+
ref: first,
|
|
2887
|
+
...(destination !== undefined ? { destination } : {}),
|
|
2888
|
+
...(selectedSwarm ? { swarm: selectedSwarm } : {}),
|
|
2889
|
+
raw: Boolean(parsed.options.raw),
|
|
2890
|
+
...(explicitRefresh !== undefined
|
|
2891
|
+
? { refresh: explicitRefresh }
|
|
2892
|
+
: {}),
|
|
2893
|
+
}, { ndjson: true }));
|
|
2894
|
+
const payload = { ...result };
|
|
2895
|
+
delete payload.destination;
|
|
2896
|
+
const closing = cliHandle;
|
|
2897
|
+
cliHandle = undefined;
|
|
2898
|
+
await closing.close();
|
|
2899
|
+
emit(payload, result.directory);
|
|
2900
|
+
break;
|
|
2901
|
+
}
|
|
2902
|
+
case "swarm create": {
|
|
2903
|
+
const created = (await client.swarms.governance("create", {
|
|
2904
|
+
...(typeof parsed.options.service === "string"
|
|
2905
|
+
? { service: parsed.options.service }
|
|
2906
|
+
: {}),
|
|
2907
|
+
...(typeof parsed.options.resume === "string"
|
|
2908
|
+
? { resume: parsed.options.resume }
|
|
2909
|
+
: {}),
|
|
2910
|
+
name: String(parsed.options.name ?? ""),
|
|
2911
|
+
description: String(parsed.options.description ?? ""),
|
|
2912
|
+
...(typeof parsed.options.alias === "string"
|
|
2913
|
+
? { alias: parsed.options.alias }
|
|
2914
|
+
: {}),
|
|
2915
|
+
}, { ndjson: true }));
|
|
2916
|
+
io.err(`Registered swarm ${created.alias ?? created.configUrl}. Saved current: ${created.savedCurrent ?? "(none)"}.`);
|
|
2917
|
+
io.err("Pivot replication is not yet confirmed. Keep this member online until a Pivot is ready; daemon will replicate automatically. Manual retry: ipab swarm replicate. Inspect readiness with ipab swarm status.");
|
|
2918
|
+
emit({ configUrl: created.configUrl }, created.configUrl);
|
|
2919
|
+
break;
|
|
2920
|
+
}
|
|
2921
|
+
case "swarm request": {
|
|
2922
|
+
const output = typeof parsed.options.output === "string"
|
|
2923
|
+
? parsed.options.output
|
|
2924
|
+
: undefined;
|
|
2925
|
+
const result = (await client.swarms.governance("request", {
|
|
2926
|
+
swarm: first,
|
|
2927
|
+
...(output !== undefined ? { output, cwd: process.cwd() } : {}),
|
|
2928
|
+
...(parsed.options.pivot ? { role: "pivot" } : {}),
|
|
2929
|
+
}, { ndjson: true }));
|
|
2930
|
+
io.err(`Owner fingerprint: ${result.ownerFingerprint}\nVerify this fingerprint through an independent trusted channel before manually sending the Request file to the Owner.`);
|
|
2931
|
+
if (result.file === undefined)
|
|
2932
|
+
io.out(JSON.stringify(result.request, null, 2));
|
|
2948
2933
|
else {
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
: {}),
|
|
2957
|
-
snapshot: Boolean(parsed.options.snapshot),
|
|
2958
|
-
});
|
|
2959
|
-
}
|
|
2960
|
-
store = context.store;
|
|
2961
|
-
if (parsed.path === "swarm create") {
|
|
2962
|
-
io.err(`Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config({ includeSecrets: false })["swarm.default"] ?? "(none)"}.`);
|
|
2963
|
-
io.err("Pivot replication is not yet confirmed. Keep this member online until a Pivot is ready; daemon will replicate automatically. Manual retry: ipab swarm replicate. Inspect readiness with ipab swarm status.");
|
|
2934
|
+
io.err(`Request saved to: ${result.file}`);
|
|
2935
|
+
if (parsed.flags.json)
|
|
2936
|
+
emit({
|
|
2937
|
+
file: result.file,
|
|
2938
|
+
member: result.request.member,
|
|
2939
|
+
ownerFingerprint: result.ownerFingerprint,
|
|
2940
|
+
}, "");
|
|
2964
2941
|
}
|
|
2965
|
-
if (contentCid)
|
|
2966
|
-
io.err(`Locally protected payload: ${contentCid}. Use ipab unpin ${contentCid} to release this CID pin only; Name subscriptions and publication/history owners remain. --snapshot links payloads directly into retained publication history, so unpin cannot release that protection.`);
|
|
2967
|
-
emit(parsed.path === "swarm create" || parsed.path === "swarm approve"
|
|
2968
|
-
? { configUrl: cid }
|
|
2969
|
-
: { cid, ...(contentCid ? { contentCid } : {}) }, cid);
|
|
2970
2942
|
break;
|
|
2971
2943
|
}
|
|
2972
|
-
case "
|
|
2944
|
+
case "swarm approve": {
|
|
2945
|
+
const { verifiedRequest, verifiedRequestStream, membershipRequestSummary, } = await import("./swarm.js");
|
|
2946
|
+
const selected = requireSwarm();
|
|
2947
|
+
if (isLocalSwarm(selected))
|
|
2948
|
+
throw new HostError(`The built-in "${LOCAL_SWARM_ALIAS}" Swarm is a single-machine Swarm and does not support swarm approve.`);
|
|
2949
|
+
if (first === "-" && !parsed.options.yes)
|
|
2950
|
+
syntax("Reading a Request from stdin requires explicit --yes; no interactive confirmation is available.");
|
|
2951
|
+
const request = first === "-"
|
|
2952
|
+
? await verifiedRequestStream((io.requestInput ?? processIO.requestInput)())
|
|
2953
|
+
: await verifiedRequest(resolve(first));
|
|
2954
|
+
if (request.configUrl !== selected)
|
|
2955
|
+
syntax(`Request belongs to ${request.configUrl}, not the selected Swarm. Use ipab --swarm ${request.configUrl} swarm approve REQUEST_FILE --yes.`);
|
|
2956
|
+
io.err(await membershipRequestSummary(request));
|
|
2957
|
+
if (!parsed.options.yes &&
|
|
2958
|
+
(!io.tty ||
|
|
2959
|
+
!(await io.confirm(`Approve the verified ${parsed.options.pivot || request.role === "pivot" ? "pivot" : "ordinary"} Request from ${request.member} above? This grants ${parsed.options.pivot || request.role === "pivot" ? "current HEAD and " : ""}the member's profile write access; all reads are public.`))))
|
|
2960
|
+
throw new HostError("Approval requires explicit --yes or interactive confirmation.");
|
|
2961
|
+
const result = (await client.swarms.governance("approve", {
|
|
2962
|
+
request,
|
|
2963
|
+
again: Boolean(parsed.options.again),
|
|
2964
|
+
pivot: Boolean(parsed.options.pivot),
|
|
2965
|
+
}, { ndjson: true }));
|
|
2966
|
+
emit({ configUrl: result.approved }, result.approved);
|
|
2967
|
+
break;
|
|
2968
|
+
}
|
|
2969
|
+
case "publish": {
|
|
2970
|
+
const named = parseNameReference(first);
|
|
2971
|
+
const targetSwarm = named?.swarm
|
|
2972
|
+
? resolveSwarm(named.swarm)
|
|
2973
|
+
: requireSwarm();
|
|
2974
|
+
const source = await resolveLocalPathIfPresent(second);
|
|
2975
|
+
const result = (await client.swarms.fsSet({
|
|
2976
|
+
swarm: targetSwarm,
|
|
2977
|
+
kind: "publish",
|
|
2978
|
+
name: first,
|
|
2979
|
+
source,
|
|
2980
|
+
...(typeof parsed.options.expect === "string"
|
|
2981
|
+
? { expect: parsed.options.expect }
|
|
2982
|
+
: {}),
|
|
2983
|
+
snapshot: Boolean(parsed.options.snapshot),
|
|
2984
|
+
}, { ndjson: true }));
|
|
2985
|
+
io.err(`Locally protected payload: ${result.contentCid}. Use ipab unpin ${result.contentCid} to release this CID pin only; Name subscriptions and publication/history owners remain. --snapshot links payloads directly into retained publication history, so unpin cannot release that protection.`);
|
|
2986
|
+
emit(result, result.cid);
|
|
2987
|
+
break;
|
|
2988
|
+
}
|
|
2989
|
+
case "store usage": {
|
|
2990
|
+
const result = await client.store.usage();
|
|
2991
|
+
emit(result, `Cached blocks: ${storageBytes(result.cachedBytes)}\nPinned blocks (deduplicated): ${storageBytes(result.pinnedBytes)}`);
|
|
2992
|
+
break;
|
|
2993
|
+
}
|
|
2973
2994
|
case "store gc": {
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
const result = await store.usage();
|
|
2977
|
-
emit(result, `Cached blocks: ${storageBytes(result.cachedBytes)}\nPinned blocks (deduplicated): ${storageBytes(result.pinnedBytes)}`);
|
|
2978
|
-
}
|
|
2979
|
-
else {
|
|
2980
|
-
const result = await store.gc();
|
|
2981
|
-
emit(result, `Removed ${result.removedBlocks} blocks; reclaimed ${storageBytes(result.reclaimedBytes)}.`);
|
|
2982
|
-
}
|
|
2995
|
+
const result = await client.store.gc({ ndjson: true });
|
|
2996
|
+
emit(result, `Removed ${result.removedBlocks} blocks; reclaimed ${storageBytes(result.reclaimedBytes)}.`);
|
|
2983
2997
|
break;
|
|
2984
2998
|
}
|
|
2985
2999
|
case "templates render":
|
|
@@ -2987,6 +3001,7 @@ async function performCli(argv, io, env) {
|
|
|
2987
3001
|
case "bundle build":
|
|
2988
3002
|
case "bundle inspect":
|
|
2989
3003
|
case "bundle import": {
|
|
3004
|
+
const { message } = await import("./errors.js");
|
|
2990
3005
|
const controller = new AbortController();
|
|
2991
3006
|
let cancelled = 0;
|
|
2992
3007
|
const interrupt = () => {
|
|
@@ -3000,147 +3015,97 @@ async function performCli(argv, io, env) {
|
|
|
3000
3015
|
process.once("SIGINT", interrupt);
|
|
3001
3016
|
process.once("SIGTERM", terminate);
|
|
3002
3017
|
try {
|
|
3003
|
-
|
|
3004
|
-
const
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
return pendingStore;
|
|
3010
|
-
};
|
|
3011
|
-
const request = {
|
|
3012
|
-
signal: controller.signal,
|
|
3013
|
-
diagnostic: (text) => {
|
|
3014
|
-
io.err(text);
|
|
3015
|
-
},
|
|
3016
|
-
resolveCid: async (cid, options) => {
|
|
3017
|
-
options.signal?.throwIfAborted();
|
|
3018
|
-
const builtin = builtins.blocks.get(cid.toV1().toString());
|
|
3019
|
-
if (builtin)
|
|
3020
|
-
return builtin.slice();
|
|
3021
|
-
return (store ?? (await getStore())).block.get(cid.toString(), options);
|
|
3022
|
-
},
|
|
3023
|
-
};
|
|
3024
|
-
const builtinSource = first ? state.pin(first) : undefined;
|
|
3025
|
-
const source = builtinSource?.builtin && builtinSource.metadata?.kind === "bundle"
|
|
3026
|
-
? builtinSource.cid
|
|
3027
|
-
: first;
|
|
3028
|
-
let selectedTemplate;
|
|
3018
|
+
const requestOpts = { signal: controller.signal, ndjson: true };
|
|
3019
|
+
const outputOpt = typeof parsed.options.output === "string"
|
|
3020
|
+
? resolve(parsed.options.output)
|
|
3021
|
+
: undefined;
|
|
3022
|
+
const outputDirOpt = String(value("bundle.outputDir"));
|
|
3023
|
+
let result;
|
|
3029
3024
|
if (parsed.path === "templates render") {
|
|
3030
|
-
const
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
}
|
|
3048
|
-
explicit ||= selector.toLowerCase().endsWith(".car");
|
|
3049
|
-
if (!explicit) {
|
|
3050
|
-
try {
|
|
3051
|
-
await lstat(selector);
|
|
3052
|
-
explicit = true;
|
|
3053
|
-
}
|
|
3054
|
-
catch (cause) {
|
|
3055
|
-
if (!nodeError(cause, "ENOENT") &&
|
|
3056
|
-
!nodeError(cause, "ENOTDIR"))
|
|
3057
|
-
throw cause;
|
|
3058
|
-
}
|
|
3059
|
-
}
|
|
3060
|
-
if (!explicit) {
|
|
3061
|
-
templateName(selector);
|
|
3062
|
-
if (!selectedSwarm)
|
|
3063
|
-
throw new HostError("Template selectors require a selected Swarm. Use --swarm or swarm use, or supply an explicit Bundle directory, CAR, exact CID or IPAB URI.");
|
|
3064
|
-
await getStore();
|
|
3065
|
-
const context = swarmContext();
|
|
3066
|
-
readContext = context;
|
|
3067
|
-
selectedTemplate = await resolveTemplateSelector(context, selector, selectedSwarm);
|
|
3068
|
-
store = context.store;
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3025
|
+
const template = await resolveLocalPathIfPresent(first);
|
|
3026
|
+
const destination = resolve(parsed.positional[2] ?? second);
|
|
3027
|
+
const parameters = [
|
|
3028
|
+
...(parsed.parameters ?? []),
|
|
3029
|
+
...(typeof parsed.options.description === "string"
|
|
3030
|
+
? [`description=${parsed.options.description}`]
|
|
3031
|
+
: []),
|
|
3032
|
+
];
|
|
3033
|
+
result = await client.store.export({
|
|
3034
|
+
mode: "render-template",
|
|
3035
|
+
template,
|
|
3036
|
+
name: second,
|
|
3037
|
+
destination,
|
|
3038
|
+
parameters,
|
|
3039
|
+
swarm: selectedSwarm,
|
|
3040
|
+
refresh: explicitRefresh,
|
|
3041
|
+
}, requestOpts);
|
|
3071
3042
|
}
|
|
3072
|
-
if (parsed.path === "
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
: "
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
:
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
...(typeof parsed.options.output === "string"
|
|
3106
|
-
? { output: parsed.options.output }
|
|
3107
|
-
: {}),
|
|
3108
|
-
outputDir: String(value("bundle.outputDir")),
|
|
3109
|
-
})
|
|
3110
|
-
: parsed.path === "bundle import"
|
|
3111
|
-
? await importBundle(first, getStore, request)
|
|
3112
|
-
: await inspectBundle(source, request);
|
|
3113
|
-
const importing = "output" in result && !parsed.options["no-import"];
|
|
3114
|
-
if (importing) {
|
|
3115
|
-
io.err("Importing build result into Store (without pinning)...");
|
|
3116
|
-
try {
|
|
3117
|
-
await importBundle(result.output, getStore, request);
|
|
3118
|
-
}
|
|
3119
|
-
catch (cause) {
|
|
3120
|
-
throw new HostError(`${message(cause)} CAR remains at ${JSON.stringify(result.output)}; retry with ipab bundle import ${JSON.stringify(result.output)}, or build with --no-import.`, 1, "IMPORT_FAILED", "authoring");
|
|
3121
|
-
}
|
|
3043
|
+
else if (parsed.path === "build") {
|
|
3044
|
+
const sourcePath = first ? resolve(first) : process.cwd();
|
|
3045
|
+
result = (await client.store.import({
|
|
3046
|
+
mode: "assemble",
|
|
3047
|
+
path: sourcePath,
|
|
3048
|
+
replace: Boolean(parsed.options.replace),
|
|
3049
|
+
output: outputOpt,
|
|
3050
|
+
outputDir: outputDirOpt,
|
|
3051
|
+
autoImport: !parsed.options["no-import"],
|
|
3052
|
+
}, requestOpts));
|
|
3053
|
+
}
|
|
3054
|
+
else if (parsed.path === "bundle build") {
|
|
3055
|
+
const sourcePath = await resolveLocalPathIfPresent(first);
|
|
3056
|
+
result = (await client.store.import({
|
|
3057
|
+
mode: "build",
|
|
3058
|
+
path: sourcePath,
|
|
3059
|
+
schemaOnly: Boolean(parsed.options["schema-only"]),
|
|
3060
|
+
replace: Boolean(parsed.options.replace),
|
|
3061
|
+
output: outputOpt,
|
|
3062
|
+
outputDir: outputDirOpt,
|
|
3063
|
+
autoImport: !parsed.options["no-import"],
|
|
3064
|
+
}, requestOpts));
|
|
3065
|
+
}
|
|
3066
|
+
else if (parsed.path === "bundle import") {
|
|
3067
|
+
const sourcePath = resolve(first);
|
|
3068
|
+
result = (await client.store.import({ mode: "car", path: sourcePath }, requestOpts));
|
|
3069
|
+
}
|
|
3070
|
+
else {
|
|
3071
|
+
const sourceRef = await resolveLocalPathIfPresent(first);
|
|
3072
|
+
result = (await client.store.inspect({
|
|
3073
|
+
ref: sourceRef,
|
|
3074
|
+
swarm: selectedSwarm,
|
|
3075
|
+
}, requestOpts));
|
|
3122
3076
|
}
|
|
3123
|
-
const closing = store;
|
|
3124
|
-
store = undefined;
|
|
3125
|
-
await closeStore(closing, undefined);
|
|
3126
|
-
state.close();
|
|
3127
|
-
state = undefined;
|
|
3128
3077
|
controller.signal.throwIfAborted();
|
|
3129
|
-
if ("output" in result)
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
emit(result, `
|
|
3078
|
+
if ("output" in result) {
|
|
3079
|
+
const importing = Boolean(result.imported);
|
|
3080
|
+
const validation = result.validation;
|
|
3081
|
+
emit(result, `CID: ${String(result.cid)}\nSchema CID: ${String(result.schemaCid)}\nCAR: ${String(result.output)}${validation !== undefined ? `\nEntry validation: ${validation?.status ?? "not-applicable"}` : ""}\nStore: ${importing ? "imported (not pinned)" : "not imported (--no-import)"}`);
|
|
3082
|
+
}
|
|
3083
|
+
else if (result.kind === "bundle-import") {
|
|
3084
|
+
const source = String(result.source);
|
|
3085
|
+
const validation = result.validation;
|
|
3086
|
+
emit(result, `Imported CID: ${String(result.cid)}\nSchema CID: ${String(result.schemaCid)}\nBlocks: ${String(result.blocks)}\n${source.toLowerCase().endsWith(".car") ? "CAR" : "Source"}: ${source}\nEntry validation: ${validation?.status ?? "not-applicable"}`);
|
|
3087
|
+
}
|
|
3133
3088
|
else if (result.kind === "project-init") {
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3089
|
+
const directory = String(result.directory);
|
|
3090
|
+
const files = Array.isArray(result.files)
|
|
3091
|
+
? result.files
|
|
3092
|
+
: [];
|
|
3093
|
+
const templateCid = typeof result.templateCid === "string"
|
|
3094
|
+
? result.templateCid
|
|
3095
|
+
: undefined;
|
|
3096
|
+
emit(result, `Created project: ${directory}${templateCid ? `\nTemplate CID: ${templateCid}` : ""}`);
|
|
3097
|
+
if (files.includes("package.json") &&
|
|
3098
|
+
(files.includes("ipab.yaml") || files.includes("ipab.json")))
|
|
3099
|
+
io.err(`Next: install declared dependencies in ${JSON.stringify(directory)}; if your template does not declare @ipab/cli, add or link it as a development dependency. Run pnpm build to prepare and package the App. Root ipab build does not compile.`);
|
|
3100
|
+
else if (files.includes(".bundle.yaml"))
|
|
3101
|
+
io.err(`Next: ipab bundle build ${JSON.stringify(directory)}`);
|
|
3102
|
+
}
|
|
3103
|
+
else {
|
|
3104
|
+
const manifest = result.manifest;
|
|
3105
|
+
const type = result.type;
|
|
3106
|
+
const validation = result.validation;
|
|
3107
|
+
emit(result, `Kind: ${String(result.kind)}\n${manifest ? `Title: ${printable(manifest.title)}\nEntry: ${manifest.entry}\nType file: ${manifest.type}\n` : ""}Type CID: ${String(result.schemaCid)}\nContent type: ${type.contentType}\nDefinition validation: passed\nStorage verification: ${validation.storage}\nEntry validation: ${validation.entry?.status ?? "not-applicable"}`);
|
|
3141
3108
|
}
|
|
3142
|
-
else
|
|
3143
|
-
emit(result, `Kind: ${result.kind}\n${result.manifest ? `Title: ${printable(result.manifest.title)}\nEntry: ${result.manifest.entry}\nType file: ${result.manifest.type}\n` : ""}Type CID: ${result.schemaCid}\nContent type: ${result.type.contentType}\nDefinition validation: passed\nStorage verification: ${result.validation.storage}\nEntry validation: ${result.validation.entry?.status ?? "not-applicable"}`);
|
|
3144
3109
|
}
|
|
3145
3110
|
catch (cause) {
|
|
3146
3111
|
if (cancelled)
|
|
@@ -3154,23 +3119,25 @@ async function performCli(argv, io, env) {
|
|
|
3154
3119
|
break;
|
|
3155
3120
|
}
|
|
3156
3121
|
case "pin list": {
|
|
3157
|
-
const listed =
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3122
|
+
const listed = await client.store.listPins();
|
|
3123
|
+
emit({
|
|
3124
|
+
items: listed.pins,
|
|
3125
|
+
builtins: listed.builtins,
|
|
3126
|
+
archived: listed.archived,
|
|
3127
|
+
}, table(["REFERENCE", "CID", "STATUS", "SOURCE"], [
|
|
3128
|
+
...listed.pins.map((pin) => [
|
|
3162
3129
|
pin.reference,
|
|
3163
3130
|
pin.cid ?? "(none)",
|
|
3164
3131
|
`${pin.status}/${pin.freshness}${pin.error ? `: ${pin.error}` : ""}`,
|
|
3165
3132
|
pin.swarm ? "following shared Name" : "fixed CID",
|
|
3166
3133
|
]),
|
|
3167
|
-
...builtins.map((pin) => [
|
|
3168
|
-
pin.name,
|
|
3169
|
-
pin.cid,
|
|
3134
|
+
...listed.builtins.map((pin) => [
|
|
3135
|
+
String(pin.name),
|
|
3136
|
+
String(pin.cid),
|
|
3170
3137
|
"read-only",
|
|
3171
3138
|
"built-in",
|
|
3172
3139
|
]),
|
|
3173
|
-
...archived.map((pin) => [
|
|
3140
|
+
...listed.archived.map((pin) => [
|
|
3174
3141
|
pin.cid,
|
|
3175
3142
|
pin.cid,
|
|
3176
3143
|
pin.status,
|
|
@@ -3180,76 +3147,86 @@ async function performCli(argv, io, env) {
|
|
|
3180
3147
|
break;
|
|
3181
3148
|
}
|
|
3182
3149
|
case "unpin": {
|
|
3183
|
-
const
|
|
3184
|
-
|
|
3185
|
-
|
|
3150
|
+
const result = await client.store.removePin(first, {
|
|
3151
|
+
...(selectedSwarm ? { swarm: selectedSwarm } : {}),
|
|
3152
|
+
});
|
|
3153
|
+
emit(result, `Unpinned ${result.reference}; released only its saved retention responsibility. No blocks deleted or GC requested.`);
|
|
3186
3154
|
break;
|
|
3187
3155
|
}
|
|
3188
3156
|
case "pin show": {
|
|
3189
|
-
const
|
|
3190
|
-
|
|
3191
|
-
:
|
|
3192
|
-
|
|
3193
|
-
? undefined
|
|
3194
|
-
: pinReference(state, first, selectedSwarm);
|
|
3195
|
-
const pin = canonical
|
|
3196
|
-
? state.contentPin(canonical.reference)
|
|
3197
|
-
: undefined;
|
|
3198
|
-
const archived = canonical
|
|
3199
|
-
? state
|
|
3200
|
-
.archivedPins()
|
|
3201
|
-
.filter((pin) => pin.cid === canonical.reference)
|
|
3202
|
-
: [];
|
|
3203
|
-
if (!pin && !builtin && !archived.length)
|
|
3204
|
-
throw new HostError(`Pin "${first}" does not exist. Run ipab pin list.`);
|
|
3205
|
-
const result = builtin
|
|
3206
|
-
? pinDetails(builtin)
|
|
3207
|
-
: {
|
|
3208
|
-
pin: pin ?? null,
|
|
3209
|
-
roots: pin ? state.hold(pin.owner)?.roots : [],
|
|
3210
|
-
archived,
|
|
3211
|
-
};
|
|
3157
|
+
const result = await client.store.getPin(first, {
|
|
3158
|
+
details: true,
|
|
3159
|
+
...(selectedSwarm ? { swarm: selectedSwarm } : {}),
|
|
3160
|
+
});
|
|
3212
3161
|
emit(result, JSON.stringify(result, null, 2));
|
|
3213
3162
|
break;
|
|
3214
3163
|
}
|
|
3215
3164
|
case "config get": {
|
|
3216
|
-
const selected =
|
|
3165
|
+
const selected = first
|
|
3166
|
+
? items.filter((item) => item.key === first)
|
|
3167
|
+
: items;
|
|
3217
3168
|
emit({ items: selected }, table(["KEY", "VALUE", "SOURCE"], selected.map((item) => [item.key, String(item.value), item.source]), "No configuration values."));
|
|
3218
3169
|
break;
|
|
3219
3170
|
}
|
|
3220
3171
|
case "config set": {
|
|
3221
3172
|
const key = configKey(first);
|
|
3222
|
-
const
|
|
3173
|
+
const rawInput = key === "pointers.apiKey"
|
|
3223
3174
|
? await (io.readSecret ?? processIO.readSecret)()
|
|
3224
|
-
: second
|
|
3225
|
-
|
|
3226
|
-
const
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
const
|
|
3175
|
+
: second;
|
|
3176
|
+
parseValue(key, rawInput, true);
|
|
3177
|
+
const updated = await client.host.setConfig(key, rawInput, {
|
|
3178
|
+
fromString: true,
|
|
3179
|
+
});
|
|
3180
|
+
const currentSource = items.find((item) => item.key === key).source;
|
|
3181
|
+
const maskSource = currentSource === "env" || currentSource === "flag"
|
|
3182
|
+
? currentSource
|
|
3183
|
+
: updated.effectiveSource === "env" ||
|
|
3184
|
+
updated.effectiveSource === "flag"
|
|
3185
|
+
? updated.effectiveSource
|
|
3186
|
+
: undefined;
|
|
3187
|
+
if (maskSource)
|
|
3188
|
+
io.err(`Warning: saved user value is masked by ${maskSource}.`);
|
|
3189
|
+
const display = {
|
|
3190
|
+
key: updated.key,
|
|
3191
|
+
value: updated.value,
|
|
3192
|
+
source: updated.source,
|
|
3193
|
+
};
|
|
3230
3194
|
emit(display, `Saved ${key} = ${printable(String(display.value))} (user).`);
|
|
3231
3195
|
break;
|
|
3232
3196
|
}
|
|
3233
|
-
case "config reset":
|
|
3234
|
-
|
|
3197
|
+
case "config reset": {
|
|
3198
|
+
await client.host.resetConfig(configKey(first));
|
|
3235
3199
|
emit({ reset: [first] }, `Reset user override: ${first}.`);
|
|
3236
3200
|
break;
|
|
3201
|
+
}
|
|
3237
3202
|
case "history list": {
|
|
3238
|
-
const page =
|
|
3239
|
-
|
|
3240
|
-
|
|
3203
|
+
const page = await client.runs.list({
|
|
3204
|
+
...(typeof parsed.options.app === "string"
|
|
3205
|
+
? { app: parsed.options.app }
|
|
3206
|
+
: {}),
|
|
3207
|
+
...(typeof parsed.options.status === "string"
|
|
3208
|
+
? { status: parsed.options.status }
|
|
3209
|
+
: {}),
|
|
3210
|
+
...(typeof parsed.options.since === "string"
|
|
3211
|
+
? { since: parsed.options.since }
|
|
3212
|
+
: {}),
|
|
3213
|
+
...(typeof parsed.options.until === "string"
|
|
3214
|
+
? { until: parsed.options.until }
|
|
3215
|
+
: {}),
|
|
3216
|
+
limit: Number(parsed.options.limit ?? value("history.limit")),
|
|
3217
|
+
...(typeof parsed.options.before === "string"
|
|
3218
|
+
? { before: parsed.options.before }
|
|
3219
|
+
: {}),
|
|
3220
|
+
});
|
|
3221
|
+
const jsonPage = { items: page.items, nextBefore: page.nextBefore };
|
|
3241
3222
|
if (parsed.flags.json) {
|
|
3242
|
-
emit(
|
|
3223
|
+
emit(jsonPage, "");
|
|
3243
3224
|
break;
|
|
3244
3225
|
}
|
|
3245
|
-
const
|
|
3246
|
-
for (const pin of state.pins())
|
|
3247
|
-
if (pin.status === "ready" && !names.has(pin.cid))
|
|
3248
|
-
names.set(pin.cid, pin.name);
|
|
3226
|
+
const pinNames = page.pinNames ?? {};
|
|
3249
3227
|
const reference = (cid) => cid === null
|
|
3250
3228
|
? "none"
|
|
3251
|
-
: cid + (
|
|
3252
|
-
const shortId = state.shortRunId.bind(state);
|
|
3229
|
+
: cid + (pinNames[cid] ? ` (${pinNames[cid]})` : "");
|
|
3253
3230
|
const rows = page.items.length
|
|
3254
3231
|
? page.items
|
|
3255
3232
|
.map((record) => [
|
|
@@ -3266,196 +3243,80 @@ async function performCli(argv, io, env) {
|
|
|
3266
3243
|
.join("\n"))
|
|
3267
3244
|
.join("\n\n")
|
|
3268
3245
|
: "No ended executions.";
|
|
3269
|
-
emit(
|
|
3246
|
+
emit(jsonPage, rows +
|
|
3270
3247
|
(page.nextBefore
|
|
3271
|
-
? `\nMore matches; use --before ${
|
|
3248
|
+
? `\nMore matches; use --before ${page.shortNextBefore ?? page.nextBefore} with the same filters.`
|
|
3272
3249
|
: ""));
|
|
3273
3250
|
break;
|
|
3274
3251
|
}
|
|
3275
3252
|
case "history show": {
|
|
3276
|
-
const record =
|
|
3277
|
-
const logs = record.
|
|
3278
|
-
|
|
3279
|
-
: undefined;
|
|
3280
|
-
emit(logs ? { ...record, logs } : record, runDetails(record) +
|
|
3253
|
+
const record = await client.runs.show(first);
|
|
3254
|
+
const logs = record.logs;
|
|
3255
|
+
emit(record, runDetails(record) +
|
|
3281
3256
|
(logs
|
|
3282
3257
|
? `\nLog recording: ${record.log}\nStdout log: ${printable(logs.stdout ?? "unavailable")}\nStderr log: ${printable(logs.stderr ?? "unavailable")}`
|
|
3283
3258
|
: "\nLog recording: disabled"));
|
|
3284
3259
|
break;
|
|
3285
3260
|
}
|
|
3286
3261
|
case "history remove": {
|
|
3287
|
-
const
|
|
3288
|
-
?
|
|
3289
|
-
:
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3262
|
+
const removeParams = parsed.positional.length
|
|
3263
|
+
? { ids: parsed.positional }
|
|
3264
|
+
: {
|
|
3265
|
+
...(typeof parsed.options.app === "string"
|
|
3266
|
+
? { app: parsed.options.app }
|
|
3267
|
+
: {}),
|
|
3268
|
+
...(typeof parsed.options.status === "string"
|
|
3269
|
+
? { status: parsed.options.status }
|
|
3270
|
+
: {}),
|
|
3271
|
+
...(typeof parsed.options.since === "string"
|
|
3272
|
+
? { since: parsed.options.since }
|
|
3273
|
+
: {}),
|
|
3274
|
+
...(typeof parsed.options.until === "string"
|
|
3275
|
+
? { until: parsed.options.until }
|
|
3276
|
+
: {}),
|
|
3277
|
+
};
|
|
3278
|
+
let idsToRemove;
|
|
3279
|
+
if (!parsed.options.yes) {
|
|
3280
|
+
const preview = await client.runs.remove({
|
|
3281
|
+
...removeParams,
|
|
3282
|
+
dryRun: true,
|
|
3283
|
+
});
|
|
3284
|
+
const ids = preview.ids ?? [];
|
|
3285
|
+
if (ids.length &&
|
|
3286
|
+
!(await io.confirm(`Remove ${ids.length} ended records selected by ${JSON.stringify(parsed.positional.length ? { ids } : parsed.options)}? Release only their retention; no GC or disk reclamation is guaranteed.`)))
|
|
3287
|
+
throw new HostError("History removal cancelled.");
|
|
3288
|
+
idsToRemove = ids;
|
|
3289
|
+
}
|
|
3290
|
+
const result = await client.runs.remove(idsToRemove !== undefined ? { ids: idsToRemove } : removeParams);
|
|
3291
|
+
emit(result, `Removed ${(result.removed ?? []).length} records; garbage collection is not guaranteed.`);
|
|
3298
3292
|
break;
|
|
3299
3293
|
}
|
|
3300
3294
|
case "exec":
|
|
3301
3295
|
case "open": {
|
|
3302
3296
|
const named = parsed.path === "open" ? parseNameReference(first) : undefined;
|
|
3303
3297
|
const registrySwarm = named?.swarm
|
|
3304
|
-
?
|
|
3298
|
+
? resolveSwarm(named.swarm)
|
|
3305
3299
|
: selectedSwarm;
|
|
3306
3300
|
if (parsed.path === "open" && !registrySwarm)
|
|
3307
3301
|
throw new HostError("Open requires a selected Swarm. Use ipab://URL_OR_ALIAS/PATH, pass --swarm URL_OR_ALIAS, or save a default with ipab swarm use URL_OR_ALIAS. To select an App directly, use ipab exec.");
|
|
3308
3302
|
if (parsed.options.log && !value("history.enabled"))
|
|
3309
3303
|
throw new HostError("Execution logging requires history.enabled=true.");
|
|
3310
|
-
await
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
: (await resolveReference(context, first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw), "local-first")).cid;
|
|
3318
|
-
store = context.store;
|
|
3319
|
-
const resolveBundleReference = async (reference, signal, preferredSwarm) => {
|
|
3320
|
-
signal.throwIfAborted();
|
|
3321
|
-
const lookup = {
|
|
3322
|
-
...swarmContext(),
|
|
3323
|
-
store: new IpfsStore(await storeConfiguration(value("store.gateway"))),
|
|
3324
|
-
};
|
|
3325
|
-
try {
|
|
3326
|
-
const named = parseNameReference(reference);
|
|
3327
|
-
const swarm = named?.swarm
|
|
3328
|
-
? state.resolveSwarm(named.swarm)
|
|
3329
|
-
: preferredSwarm
|
|
3330
|
-
? state.resolveSwarm(preferredSwarm)
|
|
3331
|
-
: selectedSwarm;
|
|
3332
|
-
const resolve = (source) => resolveReference(lookup, reference, source, (input) => state.resolve(input), false, "local-first");
|
|
3333
|
-
let resolved;
|
|
3334
|
-
try {
|
|
3335
|
-
resolved = await resolve(named ? swarm : undefined);
|
|
3336
|
-
}
|
|
3337
|
-
catch (cause) {
|
|
3338
|
-
let failure = cause;
|
|
3339
|
-
for (let depth = 0; depth < 8 && failure instanceof ContentBundleError; depth++)
|
|
3340
|
-
failure = failure.cause;
|
|
3341
|
-
if (named ||
|
|
3342
|
-
!swarm ||
|
|
3343
|
-
!(failure instanceof ContentError) ||
|
|
3344
|
-
failure.code !== "missing_block")
|
|
3345
|
-
throw cause;
|
|
3346
|
-
signal.throwIfAborted();
|
|
3347
|
-
resolved = await resolve(swarm);
|
|
3348
|
-
}
|
|
3349
|
-
signal.throwIfAborted();
|
|
3350
|
-
return { ...resolved, ...(swarm ? { swarm } : {}) };
|
|
3351
|
-
}
|
|
3352
|
-
finally {
|
|
3353
|
-
try {
|
|
3354
|
-
await lookup.finishRead?.();
|
|
3355
|
-
}
|
|
3356
|
-
finally {
|
|
3357
|
-
await lookup.store.close();
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3360
|
-
};
|
|
3361
|
-
let appCid;
|
|
3362
|
-
let appArgv;
|
|
3363
|
-
if (parsed.path === "open") {
|
|
3364
|
-
const session = localInput ? `open:${randomUUID()}` : null;
|
|
3365
|
-
const owner = await Ownership.create(state, store, `open:${randomUUID()}`, session);
|
|
3366
|
-
try {
|
|
3367
|
-
const root = localInput
|
|
3368
|
-
? await snapshotLocalBundle(localInput, owner, session, {
|
|
3369
|
-
diagnostic: (text) => {
|
|
3370
|
-
io.err(text);
|
|
3371
|
-
},
|
|
3372
|
-
})
|
|
3373
|
-
: target;
|
|
3374
|
-
const content = await validatedBundle(root, store, owner);
|
|
3375
|
-
const schema = content.schemaKey;
|
|
3376
|
-
let association;
|
|
3377
|
-
if (registrySwarm) {
|
|
3378
|
-
const lookup = {
|
|
3379
|
-
...swarmContext(),
|
|
3380
|
-
store: new IpfsStore(await storeConfiguration(value("store.gateway"))),
|
|
3381
|
-
};
|
|
3382
|
-
try {
|
|
3383
|
-
association = await swarmAssociation(lookup, registrySwarm, schema, "local-first");
|
|
3384
|
-
}
|
|
3385
|
-
finally {
|
|
3386
|
-
try {
|
|
3387
|
-
await lookup.finishRead?.();
|
|
3388
|
-
}
|
|
3389
|
-
finally {
|
|
3390
|
-
await lookup.store.close();
|
|
3391
|
-
}
|
|
3392
|
-
}
|
|
3393
|
-
}
|
|
3394
|
-
if (!association)
|
|
3395
|
-
throw new HostError(`No App registered for Schema ${schema} in Swarm ${registrySwarm}. Use ipab register set ${schema} APP_CID --swarm ${registrySwarm} or ipab exec.`);
|
|
3396
|
-
appCid = association.appCid;
|
|
3397
|
-
if (association.argv.length !== 1 || association.argv[0] !== "%")
|
|
3398
|
-
throw new HostError("Custom per-association argv is unsupported; adapt the App to accept only the content CID or use ipab exec APP_CID ARGS.");
|
|
3399
|
-
appArgv = [root];
|
|
3400
|
-
io.err("Starting App...");
|
|
3401
|
-
// execute owns the App/input context before this validation owner's eventual release.
|
|
3402
|
-
const result = await execute(state, store, { origin: "open", appCid, argv: appArgv }, {
|
|
3403
|
-
inputSchema: schema,
|
|
3404
|
-
resolveBundleReference,
|
|
3405
|
-
history: Boolean(value("history.enabled")),
|
|
3406
|
-
retain: value("output.retention") === "history",
|
|
3407
|
-
log: Boolean(parsed.options.log),
|
|
3408
|
-
diagnostic: (text) => {
|
|
3409
|
-
io.err(text);
|
|
3410
|
-
},
|
|
3411
|
-
});
|
|
3412
|
-
appExitCode = result.exitCode;
|
|
3413
|
-
return appExitCode;
|
|
3414
|
-
}
|
|
3415
|
-
finally {
|
|
3416
|
-
await owner.release();
|
|
3417
|
-
}
|
|
3418
|
-
}
|
|
3419
|
-
else if (localInput) {
|
|
3420
|
-
const session = `exec:${randomUUID()}`;
|
|
3421
|
-
const owner = await Ownership.create(state, store, `exec:${randomUUID()}`, session);
|
|
3422
|
-
try {
|
|
3423
|
-
appCid = await snapshotLocalBundle(localInput, owner, session, {
|
|
3424
|
-
diagnostic: (text) => {
|
|
3425
|
-
io.err(text);
|
|
3426
|
-
},
|
|
3427
|
-
});
|
|
3428
|
-
appArgv = parsed.positional.slice(1);
|
|
3429
|
-
io.err("Starting App...");
|
|
3430
|
-
appExitCode = (await execute(state, store, { origin: "exec", appCid, argv: appArgv }, {
|
|
3431
|
-
resolveBundleReference,
|
|
3432
|
-
history: Boolean(value("history.enabled")),
|
|
3433
|
-
retain: value("output.retention") === "history",
|
|
3434
|
-
log: Boolean(parsed.options.log),
|
|
3435
|
-
diagnostic: (text) => {
|
|
3436
|
-
io.err(text);
|
|
3437
|
-
},
|
|
3438
|
-
})).exitCode;
|
|
3439
|
-
return appExitCode;
|
|
3440
|
-
}
|
|
3441
|
-
finally {
|
|
3442
|
-
await owner.release();
|
|
3443
|
-
}
|
|
3444
|
-
}
|
|
3445
|
-
else {
|
|
3446
|
-
appCid = target;
|
|
3447
|
-
appArgv = parsed.positional.slice(1);
|
|
3448
|
-
}
|
|
3449
|
-
appExitCode = (await execute(state, store, { origin: "exec", appCid, argv: appArgv }, {
|
|
3450
|
-
resolveBundleReference,
|
|
3304
|
+
const resolvedFirst = await resolveLocalPathIfPresent(first);
|
|
3305
|
+
const prepared = await client.runs.prepare({
|
|
3306
|
+
origin: parsed.path,
|
|
3307
|
+
...(parsed.path === "open"
|
|
3308
|
+
? { target: resolvedFirst }
|
|
3309
|
+
: { appCid: resolvedFirst, argv: parsed.positional.slice(1) }),
|
|
3310
|
+
swarm: selectedSwarm,
|
|
3451
3311
|
history: Boolean(value("history.enabled")),
|
|
3452
3312
|
retain: value("output.retention") === "history",
|
|
3453
3313
|
log: Boolean(parsed.options.log),
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3314
|
+
raw: Boolean(parsed.options.raw),
|
|
3315
|
+
refresh: explicitRefresh,
|
|
3316
|
+
}, { ndjson: true });
|
|
3317
|
+
return await runPreparedApp(client, prepared, (text, prog) => {
|
|
3318
|
+
io.err(text, prog);
|
|
3319
|
+
});
|
|
3459
3320
|
}
|
|
3460
3321
|
default:
|
|
3461
3322
|
syntax("Unknown command.");
|
|
@@ -3469,15 +3330,10 @@ async function performCli(argv, io, env) {
|
|
|
3469
3330
|
}
|
|
3470
3331
|
finally {
|
|
3471
3332
|
try {
|
|
3472
|
-
|
|
3473
|
-
await readContext?.finishRead?.();
|
|
3474
|
-
}
|
|
3475
|
-
finally {
|
|
3476
|
-
await closeStore(store, appExitCode);
|
|
3477
|
-
}
|
|
3333
|
+
await cliHandle?.close();
|
|
3478
3334
|
}
|
|
3479
3335
|
finally {
|
|
3480
|
-
|
|
3336
|
+
await closeStore(daemonStore, undefined);
|
|
3481
3337
|
}
|
|
3482
3338
|
}
|
|
3483
3339
|
}
|