@ipab/cli 0.1.0-rc.8 → 0.1.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -30
- package/dist/bundled-skills.d.ts +14 -0
- package/dist/bundled-skills.d.ts.map +1 -0
- package/dist/bundled-skills.js +34 -0
- package/dist/bundled-skills.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +21 -7
- package/dist/cli.js.map +1 -1
- package/dist/daemon.d.ts +4 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +200 -0
- package/dist/daemon.js.map +1 -0
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +18 -4
- package/dist/doctor.js.map +1 -1
- package/dist/skill-source.d.ts +4 -0
- package/dist/skill-source.d.ts.map +1 -1
- package/dist/skill-source.js +14 -2
- package/dist/skill-source.js.map +1 -1
- package/dist/skills.d.ts +18 -1
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +137 -39
- package/dist/skills.js.map +1 -1
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +8 -2
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm.d.ts +2 -0
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +12 -3
- package/dist/swarm.js.map +1 -1
- package/package.json +1 -1
- package/src/bundled-skills.ts +60 -0
- package/src/cli.ts +30 -7
- package/src/daemon.ts +237 -0
- package/src/doctor.ts +42 -5
- package/src/skill-source.ts +16 -2
- package/src/skills.ts +195 -53
- package/src/swarm-files.ts +6 -2
- package/src/swarm.ts +13 -3
package/src/skills.ts
CHANGED
|
@@ -17,7 +17,8 @@ import { relativePath } from "./space.js";
|
|
|
17
17
|
import { swarmUrl } from "./config.js";
|
|
18
18
|
import type { AgentInfo } from "skills";
|
|
19
19
|
import { HostError, message, object } from "./errors.js";
|
|
20
|
-
import { nodeError } from "./authoring.js";
|
|
20
|
+
import { nodeError, scaffoldFiles } from "./authoring.js";
|
|
21
|
+
import type { bundledSkillSource } from "./skill-source.js";
|
|
21
22
|
import { getBundle } from "./get.js";
|
|
22
23
|
import {
|
|
23
24
|
privateDirectory,
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
28
29
|
import { swarmSkills, type SharedSkill, type SwarmContext } from "./swarm.js";
|
|
29
30
|
|
|
30
31
|
export const skillsInstaller = "skills@1.9.1";
|
|
32
|
+
export const bundledSkillOrigin = "bundled:ipab";
|
|
31
33
|
type Fingerprint = Record<string, string>;
|
|
32
34
|
interface Installation extends SharedSkill {
|
|
33
35
|
swarm: string;
|
|
@@ -454,7 +456,10 @@ export function parseSkillsLedger(value: unknown): Ledger {
|
|
|
454
456
|
"Invalid Skills attribution identity/path; refusing to overwrite installs.",
|
|
455
457
|
);
|
|
456
458
|
const installation: Installation = {
|
|
457
|
-
swarm:
|
|
459
|
+
swarm:
|
|
460
|
+
item.swarm === bundledSkillOrigin
|
|
461
|
+
? bundledSkillOrigin
|
|
462
|
+
: swarmUrl(ledgerString(item.swarm, "Swarm URL")),
|
|
458
463
|
path,
|
|
459
464
|
identity,
|
|
460
465
|
name: relativePath(ledgerString(item.name, "shared Name", 256)),
|
|
@@ -514,6 +519,7 @@ export interface SkillsOptions {
|
|
|
514
519
|
sync: boolean;
|
|
515
520
|
names: readonly string[];
|
|
516
521
|
agents: readonly string[];
|
|
522
|
+
overrideExisting: boolean;
|
|
517
523
|
dryRun: boolean;
|
|
518
524
|
yes: boolean;
|
|
519
525
|
tty: boolean;
|
|
@@ -576,8 +582,91 @@ export interface SkillsResult {
|
|
|
576
582
|
}[];
|
|
577
583
|
ok: boolean;
|
|
578
584
|
}
|
|
585
|
+
export async function inspectBundledSkill(
|
|
586
|
+
source: Awaited<ReturnType<typeof bundledSkillSource>>,
|
|
587
|
+
port: SkillsPort,
|
|
588
|
+
) {
|
|
589
|
+
const catalog = await port.catalog();
|
|
590
|
+
const supported = catalog.supported.filter(
|
|
591
|
+
(agent) => agent.globalSkillsDir !== null,
|
|
592
|
+
);
|
|
593
|
+
const agents = catalog.detected.filter((agent) =>
|
|
594
|
+
supported.some((entry) => entry.id === agent.id),
|
|
595
|
+
);
|
|
596
|
+
if (!agents.length)
|
|
597
|
+
return {
|
|
598
|
+
status: "not-checked" as const,
|
|
599
|
+
repairable: false,
|
|
600
|
+
message:
|
|
601
|
+
"No globally supported Agents detected for the bundled IPAB Skill.",
|
|
602
|
+
guidance: "Install an Agent, then run ipab doctor --fix.",
|
|
603
|
+
};
|
|
604
|
+
const directory = join(port.home, ".ipab", "skills");
|
|
605
|
+
await safeAncestors(directory);
|
|
606
|
+
const ledger = parseSkillsLedger(
|
|
607
|
+
await readPrivate<unknown>(
|
|
608
|
+
directory,
|
|
609
|
+
"installations.json",
|
|
610
|
+
[],
|
|
611
|
+
ledgerBytes,
|
|
612
|
+
),
|
|
613
|
+
);
|
|
614
|
+
const current = new Map<string, Fingerprint | null>();
|
|
615
|
+
const problems: string[] = [];
|
|
616
|
+
for (const saved of Object.values(ledger.installations))
|
|
617
|
+
if (saved.identity === "ipab" && saved.swarm !== bundledSkillOrigin)
|
|
618
|
+
problems.push(
|
|
619
|
+
`IPAB Skill belongs to ${saved.swarm}; use skills sync for that source.`,
|
|
620
|
+
);
|
|
621
|
+
for (const path of locations(supported, port.home, "ipab")) {
|
|
622
|
+
const files = await skillFingerprint(path);
|
|
623
|
+
current.set(pathKey(path), files);
|
|
624
|
+
const saved = ledger.installations[pathKey(path)];
|
|
625
|
+
if (
|
|
626
|
+
files &&
|
|
627
|
+
(!saved || (!equal(files, saved.files) && !recoverable(files, saved)))
|
|
628
|
+
)
|
|
629
|
+
problems.push(`Custom or locally edited IPAB Skill: ${path}`);
|
|
630
|
+
}
|
|
631
|
+
const targets = agents.map((agent) => {
|
|
632
|
+
const path = targetPath(agent, "ipab", port.home);
|
|
633
|
+
const saved = ledger.installations[pathKey(path)];
|
|
634
|
+
return {
|
|
635
|
+
path,
|
|
636
|
+
id: agent.id,
|
|
637
|
+
current: Boolean(
|
|
638
|
+
current.get(pathKey(path)) &&
|
|
639
|
+
saved?.cid === source.cid &&
|
|
640
|
+
saved.agents.includes(agent.id) &&
|
|
641
|
+
!saved.pending,
|
|
642
|
+
),
|
|
643
|
+
};
|
|
644
|
+
});
|
|
645
|
+
const description = targets
|
|
646
|
+
.map((target) => `${target.id} (${target.path})`)
|
|
647
|
+
.join(", ");
|
|
648
|
+
return {
|
|
649
|
+
status: problems.length
|
|
650
|
+
? ("invalid" as const)
|
|
651
|
+
: targets.every((target) => target.current)
|
|
652
|
+
? ("ok" as const)
|
|
653
|
+
: ("missing" as const),
|
|
654
|
+
repairable: !problems.length && targets.some((target) => !target.current),
|
|
655
|
+
message: `Bundled IPAB Skill ${source.cid}, installer ${skillsInstaller}: ${description}.${problems.length ? ` ${problems.join(" ")}` : ""}`,
|
|
656
|
+
guidance: problems.length
|
|
657
|
+
? "Preserve the existing installation; resolve its ownership or local edits before retrying. --yes never overrides conflicts."
|
|
658
|
+
: targets.every((target) => target.current)
|
|
659
|
+
? ""
|
|
660
|
+
: "Run ipab doctor --fix to install/update the CLI-bundled Skill globally for these Agents (no Swarm required; hooks/scripts are not executed).",
|
|
661
|
+
};
|
|
662
|
+
}
|
|
579
663
|
export async function manageSkills(
|
|
580
|
-
context:
|
|
664
|
+
context:
|
|
665
|
+
| SwarmContext
|
|
666
|
+
| {
|
|
667
|
+
env: NodeJS.ProcessEnv;
|
|
668
|
+
bundledSkill: Awaited<ReturnType<typeof bundledSkillSource>>;
|
|
669
|
+
},
|
|
581
670
|
swarm: string,
|
|
582
671
|
options: SkillsOptions,
|
|
583
672
|
port: SkillsPort = officialSkillsPort,
|
|
@@ -587,13 +676,7 @@ export async function manageSkills(
|
|
|
587
676
|
(agent) => agent.globalSkillsDir !== null,
|
|
588
677
|
);
|
|
589
678
|
const ids = [
|
|
590
|
-
...new Set(
|
|
591
|
-
options.agents.length
|
|
592
|
-
? options.agents
|
|
593
|
-
: catalog.detected
|
|
594
|
-
.filter((agent) => agent.globalSkillsDir !== null)
|
|
595
|
-
.map((agent) => agent.id),
|
|
596
|
-
),
|
|
679
|
+
...new Set(options.agents.length ? options.agents : ["universal"]),
|
|
597
680
|
];
|
|
598
681
|
const agents = ids.map((id) => {
|
|
599
682
|
const agent = supported.find((agent) => agent.id === id);
|
|
@@ -603,10 +686,6 @@ export async function manageSkills(
|
|
|
603
686
|
);
|
|
604
687
|
return agent;
|
|
605
688
|
});
|
|
606
|
-
if (options.sync && !agents.length)
|
|
607
|
-
throw new HostError(
|
|
608
|
-
"No globally supported agents detected. Select a target with repeatable --agent AGENT.",
|
|
609
|
-
);
|
|
610
689
|
const parent = await privateDirectory(port.home, ".ipab");
|
|
611
690
|
const directory = await privateDirectory(parent, "skills");
|
|
612
691
|
await safeAncestors(directory);
|
|
@@ -619,8 +698,10 @@ export async function manageSkills(
|
|
|
619
698
|
ledgerBytes,
|
|
620
699
|
),
|
|
621
700
|
);
|
|
622
|
-
const currentStore =
|
|
701
|
+
const currentStore =
|
|
702
|
+
"bundledSkill" in context ? undefined : storeIdentity(context);
|
|
623
703
|
const retainInstallation = async (installation: Installation) => {
|
|
704
|
+
if ("bundledSkill" in context) return;
|
|
624
705
|
const owner = installRetention(installation.path);
|
|
625
706
|
context.store.registerOwner(owner, [installation.cid]);
|
|
626
707
|
await context.store.retain(owner, [installation.cid]);
|
|
@@ -633,8 +714,10 @@ export async function manageSkills(
|
|
|
633
714
|
await retainInstallation(installation);
|
|
634
715
|
installation.files = files;
|
|
635
716
|
delete installation.pending;
|
|
636
|
-
|
|
717
|
+
if (currentStore)
|
|
718
|
+
recordRetention(installation, currentStore, [installation.cid]);
|
|
637
719
|
await saveLedger(directory, ledger);
|
|
720
|
+
if ("bundledSkill" in context) return;
|
|
638
721
|
const owner = installRetention(installation.path);
|
|
639
722
|
await context.store.recoverOwner(owner, [installation.cid]);
|
|
640
723
|
await context.store.reconcile(owner, [installation.cid]);
|
|
@@ -642,16 +725,25 @@ export async function manageSkills(
|
|
|
642
725
|
const owner = `skills-discovery:${hash(Buffer.from(swarm))}`;
|
|
643
726
|
let staging: string | undefined;
|
|
644
727
|
try {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
);
|
|
728
|
+
if (!("bundledSkill" in context))
|
|
729
|
+
await context.store.recoverOwner(owner, []);
|
|
730
|
+
const discovered =
|
|
731
|
+
"bundledSkill" in context
|
|
732
|
+
? [{ name: "ipab", identity: "ipab", cid: context.bundledSkill.cid }]
|
|
733
|
+
: await swarmSkills(context, swarm, options.names, owner);
|
|
652
734
|
const items: SkillStatus[] = [];
|
|
735
|
+
const snapshots = new Map<string, Fingerprint | null>();
|
|
653
736
|
for (const skill of discovered) {
|
|
654
737
|
const problems: string[] = [];
|
|
738
|
+
const targets = new Set(
|
|
739
|
+
agents.map((agent) =>
|
|
740
|
+
pathKey(targetPath(agent, skill.identity, port.home)),
|
|
741
|
+
),
|
|
742
|
+
);
|
|
743
|
+
const canOverride = (path: string) =>
|
|
744
|
+
options.sync &&
|
|
745
|
+
options.overrideExisting &&
|
|
746
|
+
targets.has(pathKey(path));
|
|
655
747
|
for (const saved of Object.values(ledger.installations).filter(
|
|
656
748
|
(entry) => entry.identity === skill.identity,
|
|
657
749
|
))
|
|
@@ -672,12 +764,14 @@ export async function manageSkills(
|
|
|
672
764
|
try {
|
|
673
765
|
const files = await skillFingerprint(path);
|
|
674
766
|
current.set(pathKey(path), files);
|
|
767
|
+
snapshots.set(pathKey(path), files);
|
|
675
768
|
const saved = ledger.installations[pathKey(path)];
|
|
676
|
-
if (files && !saved)
|
|
769
|
+
if (files && !saved && !canOverride(path))
|
|
677
770
|
problems.push(`Non-IPAB-managed installation: ${path}`);
|
|
678
771
|
if (
|
|
679
772
|
saved &&
|
|
680
773
|
files &&
|
|
774
|
+
!canOverride(path) &&
|
|
681
775
|
!equal(files, saved.files) &&
|
|
682
776
|
!recoverable(files, saved)
|
|
683
777
|
)
|
|
@@ -696,13 +790,17 @@ export async function manageSkills(
|
|
|
696
790
|
id: agent.id,
|
|
697
791
|
path,
|
|
698
792
|
...(saved ? { previousCid: saved.cid } : {}),
|
|
699
|
-
status:
|
|
700
|
-
? "
|
|
701
|
-
:
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
793
|
+
status: !files
|
|
794
|
+
? "not installed"
|
|
795
|
+
: canOverride(path) &&
|
|
796
|
+
(!saved ||
|
|
797
|
+
(!equal(files, saved.files) && !recoverable(files, saved)))
|
|
798
|
+
? "overwrite"
|
|
799
|
+
: saved?.pending
|
|
800
|
+
? "pending"
|
|
801
|
+
: saved?.cid === skill.cid && saved.agents.includes(agent.id)
|
|
802
|
+
? "current"
|
|
803
|
+
: "update",
|
|
706
804
|
};
|
|
707
805
|
});
|
|
708
806
|
const own = Object.values(ledger.installations).filter(
|
|
@@ -722,7 +820,9 @@ export async function manageSkills(
|
|
|
722
820
|
? "current"
|
|
723
821
|
: statuses.some(
|
|
724
822
|
(agent) =>
|
|
725
|
-
agent.status === "update" ||
|
|
823
|
+
agent.status === "update" ||
|
|
824
|
+
agent.status === "pending" ||
|
|
825
|
+
agent.status === "overwrite",
|
|
726
826
|
)
|
|
727
827
|
? "update"
|
|
728
828
|
: "not installed"
|
|
@@ -769,11 +869,17 @@ export async function manageSkills(
|
|
|
769
869
|
await mkdir(staging, { mode: 0o700 });
|
|
770
870
|
const sources = new Map<string, string>();
|
|
771
871
|
for (const skill of selected) {
|
|
772
|
-
const source =
|
|
773
|
-
context
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
872
|
+
const source =
|
|
873
|
+
"bundledSkill" in context
|
|
874
|
+
? await scaffoldFiles(
|
|
875
|
+
join(staging, skill.identity),
|
|
876
|
+
context.bundledSkill.files,
|
|
877
|
+
)
|
|
878
|
+
: await getBundle(
|
|
879
|
+
context.store,
|
|
880
|
+
skill.cid,
|
|
881
|
+
join(staging, skill.identity),
|
|
882
|
+
);
|
|
777
883
|
sources.set(skill.identity, source);
|
|
778
884
|
for (const agent of skill.agents) {
|
|
779
885
|
if (agent.status === "current" || skill.problems.length) continue;
|
|
@@ -803,7 +909,7 @@ export async function manageSkills(
|
|
|
803
909
|
);
|
|
804
910
|
options.preview(
|
|
805
911
|
[
|
|
806
|
-
`Source Swarm: ${swarm}`,
|
|
912
|
+
`Source ${swarm === bundledSkillOrigin ? "CLI" : "Swarm"}: ${swarm}`,
|
|
807
913
|
`Official installer: npx --yes --package ${skillsInstaller} skills add LOCAL --global --copy --yes --json`,
|
|
808
914
|
`Agents: ${ids.join(", ")}`,
|
|
809
915
|
...changes,
|
|
@@ -829,16 +935,28 @@ export async function manageSkills(
|
|
|
829
935
|
)))
|
|
830
936
|
)
|
|
831
937
|
throw new HostError(
|
|
832
|
-
"Skill sync requires --yes or interactive consent. --
|
|
938
|
+
"Skill sync requires --yes or interactive consent. Use --override-existing to authorize replacing existing Skills; source and link conflicts remain protected.",
|
|
833
939
|
);
|
|
834
940
|
for (const skill of selected) {
|
|
835
941
|
const source = sources.get(skill.identity)!;
|
|
942
|
+
const targets = new Set(
|
|
943
|
+
skill.agents.map((agent) => pathKey(agent.path)),
|
|
944
|
+
);
|
|
945
|
+
const canOverride = (path: string) =>
|
|
946
|
+
options.overrideExisting && targets.has(pathKey(path));
|
|
836
947
|
for (const agent of skill.agents) {
|
|
837
948
|
const key = pathKey(agent.path);
|
|
838
949
|
try {
|
|
839
950
|
await safeAncestors(agent.path);
|
|
840
951
|
let before = await skillFingerprint(agent.path);
|
|
841
952
|
const old = ledger.installations[key];
|
|
953
|
+
if (
|
|
954
|
+
canOverride(agent.path) &&
|
|
955
|
+
!equal(before, snapshots.get(key) ?? null)
|
|
956
|
+
)
|
|
957
|
+
throw new HostError(
|
|
958
|
+
`Installation changed since preview: ${agent.path}`,
|
|
959
|
+
);
|
|
842
960
|
if (agent.status === "current") {
|
|
843
961
|
if (!old || !before || !equal(before, old.files))
|
|
844
962
|
throw new HostError(
|
|
@@ -873,10 +991,13 @@ export async function manageSkills(
|
|
|
873
991
|
}
|
|
874
992
|
if (
|
|
875
993
|
before &&
|
|
876
|
-
(!old ||
|
|
877
|
-
old
|
|
878
|
-
|
|
879
|
-
|
|
994
|
+
((!old && !canOverride(agent.path)) ||
|
|
995
|
+
(old &&
|
|
996
|
+
(old.swarm !== swarm ||
|
|
997
|
+
old.name !== skill.name ||
|
|
998
|
+
(!canOverride(agent.path) &&
|
|
999
|
+
!equal(before, old.files) &&
|
|
1000
|
+
!recoverable(before, old)))))
|
|
880
1001
|
)
|
|
881
1002
|
throw new HostError(
|
|
882
1003
|
`Installation changed since preview: ${agent.path}`,
|
|
@@ -890,18 +1011,35 @@ export async function manageSkills(
|
|
|
890
1011
|
)) {
|
|
891
1012
|
const files = await skillFingerprint(path);
|
|
892
1013
|
const saved = ledger.installations[pathKey(path)];
|
|
1014
|
+
if (
|
|
1015
|
+
canOverride(path) &&
|
|
1016
|
+
!equal(files, snapshots.get(pathKey(path)) ?? null)
|
|
1017
|
+
)
|
|
1018
|
+
throw new HostError(
|
|
1019
|
+
`Protected installation changed since preview: ${path}`,
|
|
1020
|
+
);
|
|
893
1021
|
if (
|
|
894
1022
|
files &&
|
|
895
|
-
(!saved ||
|
|
896
|
-
saved
|
|
897
|
-
|
|
898
|
-
|
|
1023
|
+
((!saved && !canOverride(path)) ||
|
|
1024
|
+
(saved &&
|
|
1025
|
+
(saved.swarm !== swarm ||
|
|
1026
|
+
saved.name !== skill.name ||
|
|
1027
|
+
(!canOverride(path) &&
|
|
1028
|
+
!equal(files, saved.files) &&
|
|
1029
|
+
!recoverable(files, saved)))))
|
|
899
1030
|
)
|
|
900
1031
|
throw new HostError(
|
|
901
1032
|
`Protected installation changed since preview: ${path}`,
|
|
902
1033
|
);
|
|
903
1034
|
}
|
|
904
1035
|
before = await skillFingerprint(agent.path);
|
|
1036
|
+
if (
|
|
1037
|
+
canOverride(agent.path) &&
|
|
1038
|
+
!equal(before, snapshots.get(key) ?? null)
|
|
1039
|
+
)
|
|
1040
|
+
throw new HostError(
|
|
1041
|
+
`Installation changed since preview: ${agent.path}`,
|
|
1042
|
+
);
|
|
905
1043
|
const pending: Installation = {
|
|
906
1044
|
name: skill.name,
|
|
907
1045
|
cid: skill.cid,
|
|
@@ -920,10 +1058,11 @@ export async function manageSkills(
|
|
|
920
1058
|
pending.retentions?.find(
|
|
921
1059
|
(receipt) => receipt.store === currentStore,
|
|
922
1060
|
)?.roots ?? [];
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1061
|
+
if (currentStore)
|
|
1062
|
+
recordRetention(pending, currentStore, [
|
|
1063
|
+
...previousRoots,
|
|
1064
|
+
skill.cid,
|
|
1065
|
+
]);
|
|
927
1066
|
ledger.installations[key] = pending;
|
|
928
1067
|
await retainInstallation(pending);
|
|
929
1068
|
await saveLedger(directory, ledger);
|
|
@@ -963,6 +1102,7 @@ export async function manageSkills(
|
|
|
963
1102
|
`Official installer did not confirm the expected installation (exit ${installed.code}). Pending attribution preserved. ${installed.stderr.slice(-1000)}`,
|
|
964
1103
|
);
|
|
965
1104
|
await commitInstallation(pending, actual);
|
|
1105
|
+
snapshots.set(key, actual);
|
|
966
1106
|
agent.status = "current";
|
|
967
1107
|
skill.status = skill.agents.every(
|
|
968
1108
|
(entry) => entry.status === "current",
|
|
@@ -998,8 +1138,10 @@ export async function manageSkills(
|
|
|
998
1138
|
return result;
|
|
999
1139
|
} finally {
|
|
1000
1140
|
if (staging) await rm(staging, { recursive: true, force: true });
|
|
1001
|
-
|
|
1002
|
-
|
|
1141
|
+
if (!("bundledSkill" in context)) {
|
|
1142
|
+
await context.store.recoverOwner(owner, []);
|
|
1143
|
+
await context.store.reconcile(owner, []);
|
|
1144
|
+
}
|
|
1003
1145
|
}
|
|
1004
1146
|
});
|
|
1005
1147
|
}
|
package/src/swarm-files.ts
CHANGED
|
@@ -20,8 +20,12 @@ export async function privateDirectory(
|
|
|
20
20
|
await lstat(path);
|
|
21
21
|
} catch (cause) {
|
|
22
22
|
if (!nodeError(cause, "ENOENT")) throw cause;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
try {
|
|
24
|
+
await mkdir(path, { mode: 0o700 });
|
|
25
|
+
await secureNew(path, true);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (!nodeError(error, "EEXIST")) throw error;
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
30
|
await protectedPath(path, true);
|
|
27
31
|
return path;
|
package/src/swarm.ts
CHANGED
|
@@ -186,6 +186,8 @@ export interface MembershipRequest {
|
|
|
186
186
|
signature: string;
|
|
187
187
|
}
|
|
188
188
|
export interface SwarmContext {
|
|
189
|
+
ensureDaemon?: () => Promise<void>;
|
|
190
|
+
daemonReady?: () => Promise<() => Promise<void>>;
|
|
189
191
|
store: IpfsStore;
|
|
190
192
|
env: NodeJS.ProcessEnv;
|
|
191
193
|
stateDir: string;
|
|
@@ -1461,6 +1463,7 @@ export async function swarmDaemon(
|
|
|
1461
1463
|
await withPrivateLock(
|
|
1462
1464
|
lock,
|
|
1463
1465
|
async () => {
|
|
1466
|
+
const closeReadiness = await context.daemonReady?.();
|
|
1464
1467
|
const sessions = new Map<
|
|
1465
1468
|
string,
|
|
1466
1469
|
{
|
|
@@ -1714,8 +1717,12 @@ export async function swarmDaemon(
|
|
|
1714
1717
|
}
|
|
1715
1718
|
}
|
|
1716
1719
|
} finally {
|
|
1717
|
-
|
|
1718
|
-
|
|
1720
|
+
try {
|
|
1721
|
+
for (const [url, session] of sessions)
|
|
1722
|
+
await persist(url, session, false);
|
|
1723
|
+
} finally {
|
|
1724
|
+
await closeReadiness?.();
|
|
1725
|
+
}
|
|
1719
1726
|
}
|
|
1720
1727
|
},
|
|
1721
1728
|
signal,
|
|
@@ -1735,6 +1742,7 @@ async function activate(context: SwarmContext, record: LocalMembership) {
|
|
|
1735
1742
|
context.sourcePeers = peers;
|
|
1736
1743
|
}
|
|
1737
1744
|
context.node = node;
|
|
1745
|
+
await context.ensureDaemon?.();
|
|
1738
1746
|
}
|
|
1739
1747
|
async function localForRead(
|
|
1740
1748
|
context: SwarmContext,
|
|
@@ -2565,7 +2573,9 @@ async function lazyPrivateSource(
|
|
|
2565
2573
|
throw new HostError(
|
|
2566
2574
|
"Swarm membership changed since this cached HEAD; retry with --refresh.",
|
|
2567
2575
|
);
|
|
2568
|
-
|
|
2576
|
+
const { source } = await privateSource(scoped, record, signal);
|
|
2577
|
+
await context.ensureDaemon?.();
|
|
2578
|
+
return source;
|
|
2569
2579
|
};
|
|
2570
2580
|
// Same lock order as Owner rotation: credentials first, then the node.
|
|
2571
2581
|
return withPrivateLock(await directory(scoped), authorize, signal);
|