dsh-agent-enhancer 0.3.6 → 0.3.7
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.en.md +1 -1
- package/README.md +3 -3
- package/lib/client/instructions-skills/errors.d.ts +4 -0
- package/lib/client/instructions-skills/errors.d.ts.map +1 -1
- package/lib/client/instructions-skills/install-progress-ui.d.ts +6 -0
- package/lib/client/instructions-skills/install-progress-ui.d.ts.map +1 -0
- package/lib/client/instructions-skills/remote.d.ts +4 -1
- package/lib/client/instructions-skills/remote.d.ts.map +1 -1
- package/lib/client/instructions-skills/tab.d.ts +7 -0
- package/lib/client/instructions-skills/tab.d.ts.map +1 -1
- package/lib/client/locales.d.ts +55 -27
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/remote.d.ts.map +1 -1
- package/lib/client.js +333 -58
- package/lib/client.js.map +1 -1
- package/lib/host/index.d.ts +3 -1
- package/lib/host/index.d.ts.map +1 -1
- package/lib/host/instructions-skills/discover.d.ts.map +1 -1
- package/lib/host/instructions-skills/fs-access.d.ts +8 -0
- package/lib/host/instructions-skills/fs-access.d.ts.map +1 -0
- package/lib/host/instructions-skills/github-archive.d.ts +4 -1
- package/lib/host/instructions-skills/github-archive.d.ts.map +1 -1
- package/lib/host/instructions-skills/install-fs.d.ts +7 -2
- package/lib/host/instructions-skills/install-fs.d.ts.map +1 -1
- package/lib/host/instructions-skills/install-progress.d.ts +23 -0
- package/lib/host/instructions-skills/install-progress.d.ts.map +1 -0
- package/lib/host/instructions-skills/install.d.ts +8 -2
- package/lib/host/instructions-skills/install.d.ts.map +1 -1
- package/lib/host/instructions-skills/io.d.ts +5 -0
- package/lib/host/instructions-skills/io.d.ts.map +1 -1
- package/lib/host/instructions-skills/remove-path.d.ts +15 -0
- package/lib/host/instructions-skills/remove-path.d.ts.map +1 -1
- package/lib/host/instructions-skills/transient-paths.d.ts +15 -0
- package/lib/host/instructions-skills/transient-paths.d.ts.map +1 -0
- package/lib/host/instructions-skills/types.d.ts +15 -1
- package/lib/host/instructions-skills/types.d.ts.map +1 -1
- package/lib/host/instructions-skills/uninstall.d.ts +6 -0
- package/lib/host/instructions-skills/uninstall.d.ts.map +1 -1
- package/lib/host/instructions-skills/zip-install.d.ts.map +1 -1
- package/lib/host/rpc.d.ts +27 -0
- package/lib/host/rpc.d.ts.map +1 -1
- package/lib/identity.d.ts +1 -1
- package/lib/index.js +904 -354
- package/lib/index.js.map +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/host/index.ts
|
|
2
|
-
import { existsSync as
|
|
3
|
-
import { homedir as
|
|
4
|
-
import { join as
|
|
2
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync9, readdirSync as readdirSync7, renameSync as renameSync8, rmdirSync } from "node:fs";
|
|
3
|
+
import { homedir as homedir5 } from "node:os";
|
|
4
|
+
import { join as join30 } from "node:path";
|
|
5
5
|
import z5 from "@deepseek-ai/schemastery";
|
|
6
6
|
import { RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
7
7
|
|
|
@@ -181,7 +181,7 @@ var AuxiliaryError = class extends Error {
|
|
|
181
181
|
// src/identity.ts
|
|
182
182
|
var PACKAGE_NAME = "dsh-agent-enhancer";
|
|
183
183
|
var PLUGIN_ID = "agent-enhancer";
|
|
184
|
-
var PACKAGE_VERSION = "0.3.
|
|
184
|
+
var PACKAGE_VERSION = "0.3.7";
|
|
185
185
|
var LEGACY_PACKAGE_NAME = "dsh-composer-enhancer";
|
|
186
186
|
var ROLLBACK_PREFIX = `${PACKAGE_NAME}:rollback:`;
|
|
187
187
|
var UNDO_PREFIX = `${PACKAGE_NAME}:undo:`;
|
|
@@ -3632,7 +3632,7 @@ async function removePathBestEffort(path) {
|
|
|
3632
3632
|
return true;
|
|
3633
3633
|
} catch {
|
|
3634
3634
|
if (attempt === 2) return false;
|
|
3635
|
-
await new Promise((
|
|
3635
|
+
await new Promise((resolve16) => setTimeout(resolve16, 120 * (attempt + 1)));
|
|
3636
3636
|
}
|
|
3637
3637
|
}
|
|
3638
3638
|
return false;
|
|
@@ -4639,8 +4639,8 @@ function installMonacoRoute(ctx) {
|
|
|
4639
4639
|
}
|
|
4640
4640
|
|
|
4641
4641
|
// src/host/instructions-skills/io.ts
|
|
4642
|
-
import { existsSync as
|
|
4643
|
-
import { basename as
|
|
4642
|
+
import { existsSync as existsSync13, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
|
|
4643
|
+
import { basename as basename13, join as join24, resolve as resolve15, sep as sep7 } from "node:path";
|
|
4644
4644
|
|
|
4645
4645
|
// src/host/instructions-skills/create.ts
|
|
4646
4646
|
import { existsSync as existsSync5, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
@@ -4791,8 +4791,8 @@ function createWorkspaceSkill(projectRoot, rawName) {
|
|
|
4791
4791
|
}
|
|
4792
4792
|
|
|
4793
4793
|
// src/host/instructions-skills/discover.ts
|
|
4794
|
-
import { existsSync as
|
|
4795
|
-
import { basename as
|
|
4794
|
+
import { existsSync as existsSync9, readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
|
|
4795
|
+
import { basename as basename9, dirname as dirname7, join as join17, resolve as resolve11 } from "node:path";
|
|
4796
4796
|
|
|
4797
4797
|
// src/host/instructions-skills/types.ts
|
|
4798
4798
|
function defaultSkillInstallMeta() {
|
|
@@ -4804,15 +4804,78 @@ function defaultSkillInstallMeta() {
|
|
|
4804
4804
|
};
|
|
4805
4805
|
}
|
|
4806
4806
|
|
|
4807
|
+
// src/host/instructions-skills/transient-paths.ts
|
|
4808
|
+
import { existsSync as existsSync6, lstatSync, readdirSync, renameSync as renameSync2, rmSync, unlinkSync } from "node:fs";
|
|
4809
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
4810
|
+
import { basename as basename6, join as join13, resolve as resolve8 } from "node:path";
|
|
4811
|
+
var TRANSIENT_MARK = /\.__ae_(?:removing|installing)_/;
|
|
4812
|
+
function isTransientSkillEntryName(name2) {
|
|
4813
|
+
const base = basename6(name2.trim());
|
|
4814
|
+
if (base === "") return false;
|
|
4815
|
+
return TRANSIENT_MARK.test(base) || base.startsWith("ae-skill-removing-") || base.startsWith("ae-skill-installing-");
|
|
4816
|
+
}
|
|
4817
|
+
function skillTransientWorkPath(kind, skillName) {
|
|
4818
|
+
const safe = skillName.replace(/[^a-zA-Z0-9._-]+/g, "-").slice(0, 80) || "skill";
|
|
4819
|
+
return join13(tmpdir2(), `ae-skill-${kind}-${safe}-${process.pid}-${Date.now()}`);
|
|
4820
|
+
}
|
|
4821
|
+
function sweepTransientSkillEntries(skillsRoot) {
|
|
4822
|
+
const root = resolve8(skillsRoot);
|
|
4823
|
+
let names;
|
|
4824
|
+
try {
|
|
4825
|
+
names = readdirSync(root);
|
|
4826
|
+
} catch {
|
|
4827
|
+
return;
|
|
4828
|
+
}
|
|
4829
|
+
for (const name2 of names) {
|
|
4830
|
+
if (!isTransientSkillEntryName(name2)) continue;
|
|
4831
|
+
const full = join13(root, name2);
|
|
4832
|
+
try {
|
|
4833
|
+
rmSync(full, { recursive: true, force: true, maxRetries: 2, retryDelay: 20 });
|
|
4834
|
+
} catch {
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4838
|
+
function renameAsideToTemp(from, kind) {
|
|
4839
|
+
const absolute = resolve8(from);
|
|
4840
|
+
const preferred = skillTransientWorkPath(kind, basename6(absolute));
|
|
4841
|
+
try {
|
|
4842
|
+
renameSync2(absolute, preferred);
|
|
4843
|
+
return preferred;
|
|
4844
|
+
} catch {
|
|
4845
|
+
const sibling = `${absolute}.__ae_${kind}_${process.pid}_${Date.now()}`;
|
|
4846
|
+
renameSync2(absolute, sibling);
|
|
4847
|
+
return sibling;
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
function removeQuietly(path) {
|
|
4851
|
+
try {
|
|
4852
|
+
const stat = lstatSync(path);
|
|
4853
|
+
if (stat.isSymbolicLink()) {
|
|
4854
|
+
try {
|
|
4855
|
+
unlinkSync(path);
|
|
4856
|
+
} catch {
|
|
4857
|
+
}
|
|
4858
|
+
return;
|
|
4859
|
+
}
|
|
4860
|
+
} catch {
|
|
4861
|
+
return;
|
|
4862
|
+
}
|
|
4863
|
+
if (!existsSync6(path)) return;
|
|
4864
|
+
try {
|
|
4865
|
+
rmSync(path, { recursive: true, force: true, maxRetries: 2, retryDelay: 20 });
|
|
4866
|
+
} catch {
|
|
4867
|
+
}
|
|
4868
|
+
}
|
|
4869
|
+
|
|
4807
4870
|
// src/host/instructions-skills/uninstall.ts
|
|
4808
|
-
import { lstatSync as
|
|
4809
|
-
import { basename as
|
|
4871
|
+
import { lstatSync as lstatSync3 } from "node:fs";
|
|
4872
|
+
import { basename as basename8, dirname as dirname6, join as join16, resolve as resolve10 } from "node:path";
|
|
4810
4873
|
|
|
4811
4874
|
// src/host/instructions-skills/install-ledger.ts
|
|
4812
|
-
import { existsSync as
|
|
4813
|
-
import { dirname as dirname5, join as
|
|
4875
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
4876
|
+
import { dirname as dirname5, join as join14 } from "node:path";
|
|
4814
4877
|
function ledgerPath(dataRoot) {
|
|
4815
|
-
return
|
|
4878
|
+
return join14(dataRoot, "skills-install", "registry.json");
|
|
4816
4879
|
}
|
|
4817
4880
|
function writeLedger(dataRoot, ledger) {
|
|
4818
4881
|
const path = ledgerPath(dataRoot);
|
|
@@ -4820,11 +4883,11 @@ function writeLedger(dataRoot, ledger) {
|
|
|
4820
4883
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
4821
4884
|
writeFileSync3(tmp, `${JSON.stringify(ledger, null, 2)}
|
|
4822
4885
|
`, "utf8");
|
|
4823
|
-
|
|
4886
|
+
renameSync3(tmp, path);
|
|
4824
4887
|
}
|
|
4825
4888
|
function readInstallLedger(dataRoot) {
|
|
4826
4889
|
const path = ledgerPath(dataRoot);
|
|
4827
|
-
if (!
|
|
4890
|
+
if (!existsSync7(path)) return {};
|
|
4828
4891
|
try {
|
|
4829
4892
|
const raw = readFileSync2(path, "utf8").trim();
|
|
4830
4893
|
if (raw === "") return {};
|
|
@@ -4845,33 +4908,100 @@ function removeInstallRecord(dataRoot, name2) {
|
|
|
4845
4908
|
}
|
|
4846
4909
|
|
|
4847
4910
|
// src/host/instructions-skills/remove-path.ts
|
|
4911
|
+
import { execFileSync } from "node:child_process";
|
|
4848
4912
|
import {
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4913
|
+
chmodSync,
|
|
4914
|
+
existsSync as existsSync8,
|
|
4915
|
+
lstatSync as lstatSync2,
|
|
4916
|
+
readdirSync as readdirSync2,
|
|
4917
|
+
readlinkSync,
|
|
4918
|
+
rmSync as rmSync2,
|
|
4919
|
+
unlinkSync as unlinkSync2
|
|
4855
4920
|
} from "node:fs";
|
|
4856
|
-
import {
|
|
4921
|
+
import { homedir as homedir3 } from "node:os";
|
|
4922
|
+
import { basename as basename7, join as join15, resolve as resolve9 } from "node:path";
|
|
4923
|
+
|
|
4924
|
+
// src/host/instructions-skills/fs-access.ts
|
|
4925
|
+
var ACCESS_DENIED_RE = /eperm|eacces|eio|ebusy|access is denied|operation not permitted|file in use|still present|拒绝访问|¾Ü¾ø·ÃÎÊ/i;
|
|
4926
|
+
function nodeErrno(error) {
|
|
4927
|
+
if (typeof error !== "object" || error === null) return null;
|
|
4928
|
+
const code = Reflect.get(error, "code");
|
|
4929
|
+
return typeof code === "string" ? code : null;
|
|
4930
|
+
}
|
|
4931
|
+
function isWindowsPathBusyError(error) {
|
|
4932
|
+
const code = nodeErrno(error);
|
|
4933
|
+
if (code === "EPERM" || code === "EACCES" || code === "EBUSY" || code === "EIO") return true;
|
|
4934
|
+
const text3 = error instanceof Error ? error.message : String(error ?? "");
|
|
4935
|
+
return ACCESS_DENIED_RE.test(text3);
|
|
4936
|
+
}
|
|
4937
|
+
function busyPathHint(pathLabel) {
|
|
4938
|
+
return `Failed to update ${pathLabel}: still present (EPERM / EIO / file in use \u2014 close skill preview or Desktop file tabs, then retry)`;
|
|
4939
|
+
}
|
|
4940
|
+
|
|
4941
|
+
// src/host/instructions-skills/remove-path.ts
|
|
4857
4942
|
function pathPresent(path) {
|
|
4858
4943
|
try {
|
|
4859
|
-
|
|
4944
|
+
lstatSync2(path);
|
|
4945
|
+
return true;
|
|
4946
|
+
} catch {
|
|
4947
|
+
return false;
|
|
4948
|
+
}
|
|
4949
|
+
}
|
|
4950
|
+
function isManagedSkillEntryPath(target, env = process.env) {
|
|
4951
|
+
const absolute = resolve9(target);
|
|
4952
|
+
const managedRoots = [
|
|
4953
|
+
join15(agentsHomeOf(env), "skills"),
|
|
4954
|
+
join15(dshHomeOf(env), "skills")
|
|
4955
|
+
];
|
|
4956
|
+
for (const root of managedRoots) {
|
|
4957
|
+
if (samePath2(absolute, root) || isInsideOrSame(root, absolute)) return true;
|
|
4958
|
+
}
|
|
4959
|
+
return false;
|
|
4960
|
+
}
|
|
4961
|
+
function isProtectedExternalSkillPath(target, env = process.env) {
|
|
4962
|
+
const absolute = resolve9(target);
|
|
4963
|
+
if (isManagedSkillEntryPath(absolute, env)) return false;
|
|
4964
|
+
const home = resolve9(homedir3());
|
|
4965
|
+
const protectedRoots = [
|
|
4966
|
+
join15(home, ".skills-manager"),
|
|
4967
|
+
join15(home, ".cursor", "skills"),
|
|
4968
|
+
join15(home, ".cursor", "skills-cursor"),
|
|
4969
|
+
join15(home, ".codex", "skills"),
|
|
4970
|
+
join15(home, ".claude", "skills"),
|
|
4971
|
+
join15(home, ".codebuddy", "skills"),
|
|
4972
|
+
join15(home, ".workbuddy", "skills")
|
|
4973
|
+
];
|
|
4974
|
+
for (const root of protectedRoots) {
|
|
4975
|
+
if (samePath2(absolute, root) || isInsideOrSame(root, absolute)) return true;
|
|
4976
|
+
}
|
|
4977
|
+
return false;
|
|
4978
|
+
}
|
|
4979
|
+
function isReparseOrSymlink(path) {
|
|
4980
|
+
try {
|
|
4981
|
+
const stat = lstatSync2(path);
|
|
4982
|
+
if (stat.isSymbolicLink()) return true;
|
|
4983
|
+
if (!stat.isDirectory() && !stat.isFile()) return true;
|
|
4984
|
+
} catch {
|
|
4985
|
+
return false;
|
|
4986
|
+
}
|
|
4987
|
+
if (process.platform !== "win32") return false;
|
|
4988
|
+
try {
|
|
4989
|
+
readlinkSync(path);
|
|
4860
4990
|
return true;
|
|
4861
4991
|
} catch {
|
|
4862
4992
|
return false;
|
|
4863
4993
|
}
|
|
4864
4994
|
}
|
|
4865
4995
|
function effectivelyGone(target) {
|
|
4866
|
-
if (!pathPresent(target) && !
|
|
4996
|
+
if (!pathPresent(target) && !existsSync8(target)) return true;
|
|
4867
4997
|
try {
|
|
4868
|
-
const stat =
|
|
4998
|
+
const stat = lstatSync2(target);
|
|
4869
4999
|
if (stat.isSymbolicLink()) return false;
|
|
4870
5000
|
if (!stat.isDirectory()) return false;
|
|
4871
|
-
if (
|
|
5001
|
+
if (existsSync8(join15(target, "SKILL.md"))) return false;
|
|
4872
5002
|
let names;
|
|
4873
5003
|
try {
|
|
4874
|
-
names =
|
|
5004
|
+
names = readdirSync2(target);
|
|
4875
5005
|
} catch {
|
|
4876
5006
|
return true;
|
|
4877
5007
|
}
|
|
@@ -4880,54 +5010,100 @@ function effectivelyGone(target) {
|
|
|
4880
5010
|
return true;
|
|
4881
5011
|
}
|
|
4882
5012
|
}
|
|
4883
|
-
function
|
|
4884
|
-
const absolute = resolve8(target);
|
|
4885
|
-
if (effectivelyGone(absolute)) return;
|
|
5013
|
+
function unlinkMountOnly(absolute) {
|
|
4886
5014
|
try {
|
|
4887
|
-
|
|
4888
|
-
|
|
5015
|
+
unlinkSync2(absolute);
|
|
5016
|
+
} catch {
|
|
5017
|
+
if (process.platform === "win32") {
|
|
4889
5018
|
try {
|
|
4890
|
-
|
|
5019
|
+
execFileSync("cmd", ["/d", "/s", "/c", `rmdir "${absolute.replace(/"/g, "")}"`], {
|
|
5020
|
+
windowsHide: true,
|
|
5021
|
+
timeout: 15e3,
|
|
5022
|
+
stdio: "ignore"
|
|
5023
|
+
});
|
|
4891
5024
|
} catch {
|
|
5025
|
+
return false;
|
|
4892
5026
|
}
|
|
4893
|
-
|
|
5027
|
+
} else {
|
|
5028
|
+
return false;
|
|
4894
5029
|
}
|
|
4895
|
-
} catch {
|
|
4896
|
-
if (effectivelyGone(absolute)) return;
|
|
4897
5030
|
}
|
|
5031
|
+
return !pathPresent(absolute) && !existsSync8(absolute);
|
|
5032
|
+
}
|
|
5033
|
+
function tryUnlinkReparseOrFile(absolute) {
|
|
5034
|
+
let preferUnlink = false;
|
|
4898
5035
|
try {
|
|
4899
|
-
|
|
5036
|
+
const stat = lstatSync2(absolute);
|
|
5037
|
+
if (stat.isSymbolicLink() || stat.isFile()) preferUnlink = true;
|
|
5038
|
+
else if (!stat.isDirectory()) preferUnlink = true;
|
|
5039
|
+
else if (isReparseOrSymlink(absolute)) preferUnlink = true;
|
|
4900
5040
|
} catch {
|
|
5041
|
+
if (effectivelyGone(absolute)) return true;
|
|
4901
5042
|
}
|
|
4902
|
-
if (
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
5043
|
+
if (!preferUnlink) return false;
|
|
5044
|
+
return unlinkMountOnly(absolute);
|
|
5045
|
+
}
|
|
5046
|
+
function removePathRobust(target) {
|
|
5047
|
+
const absolute = resolve9(target);
|
|
5048
|
+
if (isProtectedExternalSkillPath(absolute)) {
|
|
5049
|
+
return;
|
|
5050
|
+
}
|
|
5051
|
+
if (!pathPresent(absolute) && !existsSync8(absolute)) return;
|
|
5052
|
+
if (isReparseOrSymlink(absolute)) {
|
|
5053
|
+
if (unlinkMountOnly(absolute)) return;
|
|
5054
|
+
if (effectivelyGone(absolute)) return;
|
|
5055
|
+
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename7(absolute)));
|
|
5056
|
+
}
|
|
5057
|
+
if (tryUnlinkReparseOrFile(absolute)) return;
|
|
5058
|
+
if (process.platform === "win32") {
|
|
4906
5059
|
try {
|
|
4907
|
-
|
|
5060
|
+
chmodSync(absolute, 438);
|
|
4908
5061
|
} catch {
|
|
4909
5062
|
}
|
|
5063
|
+
}
|
|
5064
|
+
try {
|
|
5065
|
+
rmSync2(absolute, { recursive: true, force: true, maxRetries: 3, retryDelay: 40 });
|
|
5066
|
+
} catch (error) {
|
|
5067
|
+
if (!isWindowsPathBusyError(error) && effectivelyGone(absolute)) return;
|
|
5068
|
+
}
|
|
5069
|
+
if (!pathPresent(absolute) && !existsSync8(absolute)) return;
|
|
5070
|
+
try {
|
|
5071
|
+
const aside = renameAsideToTemp(absolute, "removing");
|
|
5072
|
+
removeQuietly(aside);
|
|
4910
5073
|
return;
|
|
4911
5074
|
} catch {
|
|
4912
5075
|
}
|
|
4913
|
-
if (
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
5076
|
+
if (process.platform === "win32") {
|
|
5077
|
+
if (isReparseOrSymlink(absolute)) {
|
|
5078
|
+
if (unlinkMountOnly(absolute)) return;
|
|
5079
|
+
} else {
|
|
5080
|
+
try {
|
|
5081
|
+
execFileSync("cmd", ["/d", "/s", "/c", `rmdir /s /q "${absolute.replace(/"/g, "")}"`], {
|
|
5082
|
+
windowsHide: true,
|
|
5083
|
+
timeout: 3e4,
|
|
5084
|
+
stdio: "ignore"
|
|
5085
|
+
});
|
|
5086
|
+
} catch {
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
if (!pathPresent(absolute) && !existsSync8(absolute)) return;
|
|
5090
|
+
if (effectivelyGone(absolute)) return;
|
|
5091
|
+
}
|
|
5092
|
+
if (effectivelyGone(absolute) || !pathPresent(absolute) && !existsSync8(absolute)) return;
|
|
5093
|
+
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename7(absolute)));
|
|
4918
5094
|
}
|
|
4919
5095
|
|
|
4920
5096
|
// src/host/instructions-skills/uninstall.ts
|
|
4921
5097
|
function skillEntryPath(skillMdOrBundlePath) {
|
|
4922
|
-
const absolute =
|
|
4923
|
-
const base =
|
|
5098
|
+
const absolute = resolve10(skillMdOrBundlePath);
|
|
5099
|
+
const base = basename8(absolute);
|
|
4924
5100
|
if (base.toLowerCase() === "skill.md") return dirname6(absolute);
|
|
4925
5101
|
if (base.toLowerCase().endsWith(".md")) return absolute;
|
|
4926
5102
|
return absolute;
|
|
4927
5103
|
}
|
|
4928
5104
|
function pathPresent2(path) {
|
|
4929
5105
|
try {
|
|
4930
|
-
|
|
5106
|
+
lstatSync3(path);
|
|
4931
5107
|
return true;
|
|
4932
5108
|
} catch {
|
|
4933
5109
|
return false;
|
|
@@ -4936,8 +5112,8 @@ function pathPresent2(path) {
|
|
|
4936
5112
|
function managedSkillEntriesForName(root, name2) {
|
|
4937
5113
|
if (!isKebabCaseName(name2)) return [];
|
|
4938
5114
|
const out = [];
|
|
4939
|
-
const asDir =
|
|
4940
|
-
const asFile =
|
|
5115
|
+
const asDir = join16(root, name2);
|
|
5116
|
+
const asFile = join16(root, `${name2}.md`);
|
|
4941
5117
|
for (const entry of [asDir, asFile]) {
|
|
4942
5118
|
if (!pathPresent2(entry)) continue;
|
|
4943
5119
|
if (!samePath2(dirname6(entry), root)) continue;
|
|
@@ -4950,8 +5126,8 @@ function resolveManagedSkillRemovalTarget(path, name2, managedRoots) {
|
|
|
4950
5126
|
if (!isKebabCaseName(name2)) return null;
|
|
4951
5127
|
const entry = skillEntryPath(path);
|
|
4952
5128
|
for (const root of managedRoots) {
|
|
4953
|
-
const asDir =
|
|
4954
|
-
const asFile =
|
|
5129
|
+
const asDir = join16(root, name2);
|
|
5130
|
+
const asFile = join16(root, `${name2}.md`);
|
|
4955
5131
|
if (samePath2(entry, asDir) || samePath2(entry, asFile)) {
|
|
4956
5132
|
if (!pathPresent2(entry)) return null;
|
|
4957
5133
|
if (!samePath2(dirname6(entry), root)) return null;
|
|
@@ -4971,18 +5147,20 @@ function purgeManagedSkillName(options) {
|
|
|
4971
5147
|
if (!isKebabCaseName(name2)) {
|
|
4972
5148
|
throw new AuxiliaryError("FILE_DENIED", `Invalid skill name: ${name2}`);
|
|
4973
5149
|
}
|
|
5150
|
+
const except = (options.exceptPaths ?? []).map((entry) => resolve10(entry));
|
|
4974
5151
|
const roots = skillRootsFor(options.cwd, options.projectRoot, options.env);
|
|
4975
5152
|
const purgeTargets = /* @__PURE__ */ new Set();
|
|
4976
5153
|
for (const extra of options.also ?? []) {
|
|
4977
|
-
purgeTargets.add(
|
|
5154
|
+
purgeTargets.add(resolve10(extra));
|
|
4978
5155
|
}
|
|
4979
5156
|
for (const root of roots) {
|
|
4980
5157
|
for (const entry of managedSkillEntriesForName(root, name2)) {
|
|
4981
|
-
purgeTargets.add(
|
|
5158
|
+
purgeTargets.add(resolve10(entry));
|
|
4982
5159
|
}
|
|
4983
5160
|
}
|
|
4984
5161
|
const removed = [];
|
|
4985
5162
|
for (const entry of purgeTargets) {
|
|
5163
|
+
if (except.some((skip) => samePath2(skip, entry))) continue;
|
|
4986
5164
|
removePathRobust(entry);
|
|
4987
5165
|
removed.push(entry);
|
|
4988
5166
|
}
|
|
@@ -5017,54 +5195,54 @@ function uninstallManagedSkill(options) {
|
|
|
5017
5195
|
|
|
5018
5196
|
// src/host/instructions-skills/discover.ts
|
|
5019
5197
|
function entryId(scope, path) {
|
|
5020
|
-
return `${scope}:${
|
|
5198
|
+
return `${scope}:${resolve11(path).toLowerCase()}`;
|
|
5021
5199
|
}
|
|
5022
5200
|
function pushUnique(out, seen, entry) {
|
|
5023
|
-
const key =
|
|
5201
|
+
const key = resolve11(entry.path).toLowerCase();
|
|
5024
5202
|
if (seen.has(key)) return;
|
|
5025
5203
|
seen.add(key);
|
|
5026
5204
|
out.push(entry);
|
|
5027
5205
|
}
|
|
5028
5206
|
function discoverInstructionFiles(options) {
|
|
5029
5207
|
const env = options.env ?? process.env;
|
|
5030
|
-
const cwd =
|
|
5208
|
+
const cwd = resolve11(options.cwd);
|
|
5031
5209
|
const projectRoot = findProjectRoot(cwd);
|
|
5032
5210
|
const seen = /* @__PURE__ */ new Set();
|
|
5033
5211
|
const instructions = [];
|
|
5034
|
-
const globalPath =
|
|
5212
|
+
const globalPath = join17(dshHomeOf(env), "AGENTS.md");
|
|
5035
5213
|
pushUnique(instructions, seen, {
|
|
5036
5214
|
id: entryId("global", globalPath),
|
|
5037
5215
|
scope: "global",
|
|
5038
5216
|
name: "AGENTS.md",
|
|
5039
5217
|
path: globalPath,
|
|
5040
|
-
exists:
|
|
5218
|
+
exists: existsSync9(globalPath),
|
|
5041
5219
|
bytes: fileBytes(globalPath),
|
|
5042
5220
|
createable: false
|
|
5043
5221
|
});
|
|
5044
|
-
const sharedPath =
|
|
5222
|
+
const sharedPath = join17(agentsHomeOf(env), "AGENTS.md");
|
|
5045
5223
|
pushUnique(instructions, seen, {
|
|
5046
5224
|
id: entryId("shared", sharedPath),
|
|
5047
5225
|
scope: "shared",
|
|
5048
5226
|
name: "AGENTS.md",
|
|
5049
5227
|
path: sharedPath,
|
|
5050
|
-
exists:
|
|
5228
|
+
exists: existsSync9(sharedPath),
|
|
5051
5229
|
bytes: fileBytes(sharedPath),
|
|
5052
5230
|
createable: false
|
|
5053
5231
|
});
|
|
5054
|
-
const rootAgents =
|
|
5232
|
+
const rootAgents = join17(projectRoot, "AGENTS.md");
|
|
5055
5233
|
pushUnique(instructions, seen, {
|
|
5056
5234
|
id: entryId("project", rootAgents),
|
|
5057
5235
|
scope: "project",
|
|
5058
5236
|
name: "AGENTS.md",
|
|
5059
5237
|
path: rootAgents,
|
|
5060
|
-
exists:
|
|
5238
|
+
exists: existsSync9(rootAgents),
|
|
5061
5239
|
bytes: fileBytes(rootAgents),
|
|
5062
|
-
createable: !
|
|
5240
|
+
createable: !existsSync9(rootAgents)
|
|
5063
5241
|
});
|
|
5064
5242
|
for (const dir of projectChainDirs(projectRoot, cwd)) {
|
|
5065
5243
|
for (const name2 of INSTRUCTION_CANDIDATES) {
|
|
5066
|
-
const path =
|
|
5067
|
-
if (!
|
|
5244
|
+
const path = join17(dir, name2);
|
|
5245
|
+
if (!existsSync9(path)) continue;
|
|
5068
5246
|
if (samePath2(path, rootAgents)) continue;
|
|
5069
5247
|
pushUnique(instructions, seen, {
|
|
5070
5248
|
id: entryId("project", path),
|
|
@@ -5099,21 +5277,23 @@ function discoverFilesystemSkills(options) {
|
|
|
5099
5277
|
const byName = /* @__PURE__ */ new Map();
|
|
5100
5278
|
for (const root of roots) {
|
|
5101
5279
|
const managedRoot = managed.some((path) => samePath2(path, root));
|
|
5280
|
+
if (managedRoot) sweepTransientSkillEntries(root);
|
|
5102
5281
|
let names;
|
|
5103
5282
|
try {
|
|
5104
|
-
names =
|
|
5283
|
+
names = readdirSync3(root);
|
|
5105
5284
|
} catch {
|
|
5106
5285
|
continue;
|
|
5107
5286
|
}
|
|
5108
5287
|
for (const name2 of names) {
|
|
5109
|
-
|
|
5110
|
-
|
|
5288
|
+
if (isTransientSkillEntryName(name2)) continue;
|
|
5289
|
+
const skillMd = join17(root, name2, "SKILL.md");
|
|
5290
|
+
if (!existsSync9(skillMd)) continue;
|
|
5111
5291
|
if (byName.has(name2)) continue;
|
|
5112
5292
|
byName.set(name2, {
|
|
5113
|
-
id: `fs:${
|
|
5293
|
+
id: `fs:${resolve11(skillMd).toLowerCase()}`,
|
|
5114
5294
|
name: name2,
|
|
5115
5295
|
description: descriptionFromSkillMd(skillMd),
|
|
5116
|
-
path:
|
|
5296
|
+
path: resolve11(skillMd),
|
|
5117
5297
|
provider: dirnameLabel(root, options.projectRoot, env),
|
|
5118
5298
|
modelInvocable: null,
|
|
5119
5299
|
userInvocable: null,
|
|
@@ -5126,12 +5306,12 @@ function discoverFilesystemSkills(options) {
|
|
|
5126
5306
|
return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
5127
5307
|
}
|
|
5128
5308
|
function dirnameLabel(root, projectRoot, env) {
|
|
5129
|
-
if (samePath2(root,
|
|
5130
|
-
if (samePath2(root,
|
|
5131
|
-
if (samePath2(root,
|
|
5132
|
-
if (samePath2(root,
|
|
5133
|
-
const parent =
|
|
5134
|
-
const leaf =
|
|
5309
|
+
if (samePath2(root, join17(projectRoot, ".agents", "skills"))) return "project";
|
|
5310
|
+
if (samePath2(root, join17(projectRoot, ".dsh", "skills"))) return "project-dsh";
|
|
5311
|
+
if (samePath2(root, join17(agentsHomeOf(env), "skills"))) return "shared";
|
|
5312
|
+
if (samePath2(root, join17(dshHomeOf(env), "skills"))) return "dsh-home";
|
|
5313
|
+
const parent = basename9(dirname7(root)).toLowerCase();
|
|
5314
|
+
const leaf = basename9(root).toLowerCase();
|
|
5135
5315
|
if (parent === ".cursor" && leaf === "skills") return "cursor";
|
|
5136
5316
|
if (parent === ".cursor" && leaf === "skills-cursor") return "cursor-builtin";
|
|
5137
5317
|
if (parent === ".codex") return "codex";
|
|
@@ -5149,7 +5329,7 @@ function normalizeRegistrySkills(raw) {
|
|
|
5149
5329
|
const name2 = typeof row.name === "string" ? row.name.trim() : "";
|
|
5150
5330
|
if (name2 === "" || seen.has(name2)) continue;
|
|
5151
5331
|
seen.add(name2);
|
|
5152
|
-
const path = typeof row.path === "string" && row.path.trim() !== "" ?
|
|
5332
|
+
const path = typeof row.path === "string" && row.path.trim() !== "" ? resolve11(row.path.trim()) : null;
|
|
5153
5333
|
out.push({
|
|
5154
5334
|
id: path !== null ? `reg:${path.toLowerCase()}` : `reg:${name2}`,
|
|
5155
5335
|
name: name2,
|
|
@@ -5166,24 +5346,24 @@ function normalizeRegistrySkills(raw) {
|
|
|
5166
5346
|
}
|
|
5167
5347
|
function coerceSkillDocumentPath(path, _name) {
|
|
5168
5348
|
if (path === null || path.trim() === "") return null;
|
|
5169
|
-
const absolute =
|
|
5170
|
-
if (
|
|
5349
|
+
const absolute = resolve11(path.trim());
|
|
5350
|
+
if (existsSync9(absolute)) {
|
|
5171
5351
|
try {
|
|
5172
5352
|
if (statSync2(absolute).isFile()) return absolute;
|
|
5173
5353
|
} catch {
|
|
5174
5354
|
}
|
|
5175
|
-
const asFile =
|
|
5176
|
-
if (
|
|
5355
|
+
const asFile = join17(absolute, "SKILL.md");
|
|
5356
|
+
if (existsSync9(asFile)) return asFile;
|
|
5177
5357
|
}
|
|
5178
5358
|
const lower = absolute.toLowerCase();
|
|
5179
5359
|
if (lower.endsWith("skill.md") || lower.endsWith(".md")) return absolute;
|
|
5180
|
-
const nested =
|
|
5181
|
-
return
|
|
5360
|
+
const nested = join17(absolute, "SKILL.md");
|
|
5361
|
+
return existsSync9(nested) ? nested : absolute;
|
|
5182
5362
|
}
|
|
5183
5363
|
function resolveSkillPathFromRoots(name2, cwd, projectRoot, env) {
|
|
5184
5364
|
for (const root of previewSkillSearchRoots(cwd, projectRoot, env)) {
|
|
5185
|
-
const skillMd =
|
|
5186
|
-
if (
|
|
5365
|
+
const skillMd = join17(root, name2, "SKILL.md");
|
|
5366
|
+
if (existsSync9(skillMd)) return resolve11(skillMd);
|
|
5187
5367
|
}
|
|
5188
5368
|
return null;
|
|
5189
5369
|
}
|
|
@@ -5343,10 +5523,10 @@ function parseGitSkillSource(raw) {
|
|
|
5343
5523
|
}
|
|
5344
5524
|
|
|
5345
5525
|
// src/host/instructions-skills/install.ts
|
|
5346
|
-
import { execFile as execFile3 } from "node:child_process";
|
|
5347
|
-
import { existsSync as
|
|
5348
|
-
import { tmpdir as
|
|
5349
|
-
import { basename as
|
|
5526
|
+
import { execFile as execFile3, spawn } from "node:child_process";
|
|
5527
|
+
import { existsSync as existsSync11, mkdtempSync, realpathSync, rmSync as rmSync4 } from "node:fs";
|
|
5528
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
5529
|
+
import { basename as basename11, dirname as dirname9, join as join21, resolve as resolve13 } from "node:path";
|
|
5350
5530
|
import { promisify as promisify3 } from "node:util";
|
|
5351
5531
|
|
|
5352
5532
|
// src/host/instructions-skills/github-archive.ts
|
|
@@ -5354,12 +5534,12 @@ import { execFile as execFile2 } from "node:child_process";
|
|
|
5354
5534
|
import {
|
|
5355
5535
|
createWriteStream,
|
|
5356
5536
|
mkdirSync as mkdirSync4,
|
|
5357
|
-
readdirSync as
|
|
5537
|
+
readdirSync as readdirSync4,
|
|
5358
5538
|
renameSync as renameSync4,
|
|
5359
|
-
rmSync as
|
|
5539
|
+
rmSync as rmSync3,
|
|
5360
5540
|
statSync as statSync3
|
|
5361
5541
|
} from "node:fs";
|
|
5362
|
-
import { join as
|
|
5542
|
+
import { join as join18 } from "node:path";
|
|
5363
5543
|
import { Readable } from "node:stream";
|
|
5364
5544
|
import { pipeline } from "node:stream/promises";
|
|
5365
5545
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -5371,7 +5551,7 @@ function detailOf(error) {
|
|
|
5371
5551
|
const body = [error.message, stderr.trim()].filter((part) => part !== "").join("\n");
|
|
5372
5552
|
return body.slice(0, 800);
|
|
5373
5553
|
}
|
|
5374
|
-
async function downloadUrl(url, destFile, signal) {
|
|
5554
|
+
async function downloadUrl(url, destFile, signal, onBytes) {
|
|
5375
5555
|
signal.throwIfAborted();
|
|
5376
5556
|
const response = await fetch(url, {
|
|
5377
5557
|
signal,
|
|
@@ -5387,11 +5567,20 @@ async function downloadUrl(url, destFile, signal) {
|
|
|
5387
5567
|
if (response.body === null) {
|
|
5388
5568
|
throw new Error(`Empty body from ${url}`);
|
|
5389
5569
|
}
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5570
|
+
const lengthHeader = response.headers.get("content-length");
|
|
5571
|
+
const parsedTotal = lengthHeader !== null ? Number(lengthHeader) : Number.NaN;
|
|
5572
|
+
const bytesTotal = Number.isFinite(parsedTotal) && parsedTotal > 0 ? parsedTotal : null;
|
|
5573
|
+
let bytesReceived = 0;
|
|
5574
|
+
onBytes?.(0, bytesTotal);
|
|
5575
|
+
const source = Readable.fromWeb(response.body);
|
|
5576
|
+
source.on("data", (chunk) => {
|
|
5577
|
+
const size = typeof chunk === "string" ? Buffer.byteLength(chunk) : chunk.byteLength;
|
|
5578
|
+
bytesReceived += size;
|
|
5579
|
+
onBytes?.(bytesReceived, bytesTotal);
|
|
5580
|
+
});
|
|
5581
|
+
await pipeline(source, createWriteStream(destFile));
|
|
5394
5582
|
signal.throwIfAborted();
|
|
5583
|
+
onBytes?.(bytesReceived, bytesTotal);
|
|
5395
5584
|
}
|
|
5396
5585
|
async function extractZip(zipPath, destDir, signal) {
|
|
5397
5586
|
signal.throwIfAborted();
|
|
@@ -5409,12 +5598,12 @@ async function extractZip(zipPath, destDir, signal) {
|
|
|
5409
5598
|
function unwrapArchiveRoot(extractDir) {
|
|
5410
5599
|
let entries;
|
|
5411
5600
|
try {
|
|
5412
|
-
entries =
|
|
5601
|
+
entries = readdirSync4(extractDir).filter((name2) => name2 !== "__MACOSX");
|
|
5413
5602
|
} catch {
|
|
5414
5603
|
return extractDir;
|
|
5415
5604
|
}
|
|
5416
5605
|
if (entries.length !== 1) return extractDir;
|
|
5417
|
-
const only =
|
|
5606
|
+
const only = join18(extractDir, entries[0]);
|
|
5418
5607
|
try {
|
|
5419
5608
|
if (statSync3(only).isDirectory()) return only;
|
|
5420
5609
|
} catch {
|
|
@@ -5422,33 +5611,69 @@ function unwrapArchiveRoot(extractDir) {
|
|
|
5422
5611
|
}
|
|
5423
5612
|
return only;
|
|
5424
5613
|
}
|
|
5425
|
-
async function
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5614
|
+
async function resolveDefaultBranch(owner, repo, signal) {
|
|
5615
|
+
signal.throwIfAborted();
|
|
5616
|
+
try {
|
|
5617
|
+
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
|
|
5618
|
+
signal,
|
|
5619
|
+
headers: {
|
|
5620
|
+
Accept: "application/vnd.github+json",
|
|
5621
|
+
"User-Agent": "dsh-agent-enhancer-skill-install"
|
|
5622
|
+
}
|
|
5623
|
+
});
|
|
5624
|
+
if (!response.ok) return null;
|
|
5625
|
+
const body = await response.json();
|
|
5626
|
+
return typeof body.default_branch === "string" && body.default_branch.trim() !== "" ? body.default_branch.trim() : null;
|
|
5627
|
+
} catch {
|
|
5628
|
+
return null;
|
|
5629
|
+
}
|
|
5630
|
+
}
|
|
5631
|
+
function archiveCandidates(owner, repo, defaultBranch) {
|
|
5632
|
+
const urls = [];
|
|
5633
|
+
if (defaultBranch !== null) {
|
|
5634
|
+
urls.push(`https://codeload.github.com/${owner}/${repo}/zip/refs/heads/${encodeURIComponent(defaultBranch)}`);
|
|
5635
|
+
}
|
|
5636
|
+
urls.push(
|
|
5432
5637
|
`https://api.github.com/repos/${owner}/${repo}/zipball`,
|
|
5433
5638
|
`https://codeload.github.com/${owner}/${repo}/zip/refs/heads/main`,
|
|
5434
5639
|
`https://codeload.github.com/${owner}/${repo}/zip/refs/heads/master`
|
|
5435
|
-
|
|
5640
|
+
);
|
|
5641
|
+
return [...new Set(urls)];
|
|
5642
|
+
}
|
|
5643
|
+
async function fetchGithubRepoArchive(options) {
|
|
5644
|
+
const { owner, repo, workDir, signal, onDownloadProgress, onStage } = options;
|
|
5645
|
+
mkdirSync4(workDir, { recursive: true });
|
|
5646
|
+
const zipPath = join18(workDir, "repo.zip");
|
|
5647
|
+
const extractDir = join18(workDir, "extract");
|
|
5648
|
+
mkdirSync4(extractDir, { recursive: true });
|
|
5649
|
+
const defaultBranch = await resolveDefaultBranch(owner, repo, signal);
|
|
5650
|
+
const candidates = archiveCandidates(owner, repo, defaultBranch);
|
|
5436
5651
|
const errors = [];
|
|
5437
|
-
|
|
5652
|
+
let downloadStarted = false;
|
|
5653
|
+
for (let index = 0; index < candidates.length; index += 1) {
|
|
5654
|
+
const url = candidates[index];
|
|
5438
5655
|
signal.throwIfAborted();
|
|
5439
5656
|
try {
|
|
5440
|
-
|
|
5441
|
-
|
|
5657
|
+
rmSync3(zipPath, { force: true });
|
|
5658
|
+
rmSync3(extractDir, { recursive: true, force: true });
|
|
5442
5659
|
mkdirSync4(extractDir, { recursive: true });
|
|
5443
|
-
|
|
5660
|
+
const detail = index === 0 ? `${owner}/${repo}` : `${owner}/${repo} \xB7 retry ${index + 1}/${candidates.length}`;
|
|
5661
|
+
if (!downloadStarted) {
|
|
5662
|
+
onStage?.("downloading", detail);
|
|
5663
|
+
downloadStarted = true;
|
|
5664
|
+
} else {
|
|
5665
|
+
onStage?.("downloading", detail);
|
|
5666
|
+
}
|
|
5667
|
+
await downloadUrl(url, zipPath, signal, onDownloadProgress);
|
|
5668
|
+
onStage?.("extracting", `${owner}/${repo}`);
|
|
5444
5669
|
await extractZip(zipPath, extractDir, signal);
|
|
5445
5670
|
const root = unwrapArchiveRoot(extractDir);
|
|
5446
|
-
const repoDir =
|
|
5447
|
-
|
|
5671
|
+
const repoDir = join18(workDir, "repo");
|
|
5672
|
+
rmSync3(repoDir, { recursive: true, force: true });
|
|
5448
5673
|
renameSync4(root, repoDir);
|
|
5449
5674
|
try {
|
|
5450
|
-
|
|
5451
|
-
|
|
5675
|
+
rmSync3(zipPath, { force: true });
|
|
5676
|
+
rmSync3(extractDir, { recursive: true, force: true });
|
|
5452
5677
|
} catch {
|
|
5453
5678
|
}
|
|
5454
5679
|
return repoDir;
|
|
@@ -5473,14 +5698,15 @@ async function fetchGithubRepoArchive(options) {
|
|
|
5473
5698
|
// src/host/instructions-skills/install-fs.ts
|
|
5474
5699
|
import {
|
|
5475
5700
|
cpSync,
|
|
5476
|
-
existsSync as
|
|
5477
|
-
lstatSync as
|
|
5701
|
+
existsSync as existsSync10,
|
|
5702
|
+
lstatSync as lstatSync4,
|
|
5478
5703
|
mkdirSync as mkdirSync5,
|
|
5479
|
-
readdirSync as
|
|
5704
|
+
readdirSync as readdirSync5,
|
|
5480
5705
|
readFileSync as readFileSync4,
|
|
5706
|
+
renameSync as renameSync5,
|
|
5481
5707
|
symlinkSync
|
|
5482
5708
|
} from "node:fs";
|
|
5483
|
-
import { basename as
|
|
5709
|
+
import { basename as basename10, dirname as dirname8, join as join19, resolve as resolve12 } from "node:path";
|
|
5484
5710
|
function frontmatterBlock(path) {
|
|
5485
5711
|
try {
|
|
5486
5712
|
const text3 = readFileSync4(path, "utf8");
|
|
@@ -5500,14 +5726,14 @@ function nameFromSkillPath(path, fallback) {
|
|
|
5500
5726
|
return fallback;
|
|
5501
5727
|
}
|
|
5502
5728
|
function directoryBundleName(dir, folderName) {
|
|
5503
|
-
return nameFromSkillPath(
|
|
5729
|
+
return nameFromSkillPath(join19(dir, "SKILL.md"), folderName);
|
|
5504
5730
|
}
|
|
5505
5731
|
function findSkillBundles(root) {
|
|
5506
|
-
const absolute =
|
|
5507
|
-
if (!
|
|
5508
|
-
const rootSkill =
|
|
5509
|
-
if (
|
|
5510
|
-
const folderName =
|
|
5732
|
+
const absolute = resolve12(root);
|
|
5733
|
+
if (!existsSync10(absolute)) return [];
|
|
5734
|
+
const rootSkill = join19(absolute, "SKILL.md");
|
|
5735
|
+
if (existsSync10(rootSkill)) {
|
|
5736
|
+
const folderName = basename10(absolute);
|
|
5511
5737
|
const name2 = directoryBundleName(absolute, folderName);
|
|
5512
5738
|
if (isKebabCaseName(name2)) {
|
|
5513
5739
|
return [{ name: name2, sourcePath: absolute, kind: "directory" }];
|
|
@@ -5516,13 +5742,14 @@ function findSkillBundles(root) {
|
|
|
5516
5742
|
const out = [];
|
|
5517
5743
|
let entries;
|
|
5518
5744
|
try {
|
|
5519
|
-
entries =
|
|
5745
|
+
entries = readdirSync5(absolute);
|
|
5520
5746
|
} catch {
|
|
5521
5747
|
return [];
|
|
5522
5748
|
}
|
|
5523
5749
|
for (const entry of entries) {
|
|
5524
|
-
|
|
5525
|
-
|
|
5750
|
+
if (isTransientSkillEntryName(entry)) continue;
|
|
5751
|
+
const full = join19(absolute, entry);
|
|
5752
|
+
if (existsSync10(join19(full, "SKILL.md"))) {
|
|
5526
5753
|
const name2 = directoryBundleName(full, entry);
|
|
5527
5754
|
if (!isKebabCaseName(name2)) continue;
|
|
5528
5755
|
out.push({ name: name2, sourcePath: full, kind: "directory" });
|
|
@@ -5530,7 +5757,7 @@ function findSkillBundles(root) {
|
|
|
5530
5757
|
}
|
|
5531
5758
|
let isFile = false;
|
|
5532
5759
|
try {
|
|
5533
|
-
isFile =
|
|
5760
|
+
isFile = lstatSync4(full).isFile();
|
|
5534
5761
|
} catch {
|
|
5535
5762
|
continue;
|
|
5536
5763
|
}
|
|
@@ -5543,13 +5770,13 @@ function findSkillBundles(root) {
|
|
|
5543
5770
|
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
5544
5771
|
}
|
|
5545
5772
|
function resolveBundlesFromClone(cloneRoot, subpath) {
|
|
5546
|
-
const base = subpath === null || subpath === "" ?
|
|
5547
|
-
if (!
|
|
5773
|
+
const base = subpath === null || subpath === "" ? resolve12(cloneRoot) : resolve12(cloneRoot, subpath);
|
|
5774
|
+
if (!existsSync10(base)) {
|
|
5548
5775
|
throw new AuxiliaryError("FILE_NOT_FOUND", `Path not found in repository: ${subpath ?? "."}`);
|
|
5549
5776
|
}
|
|
5550
|
-
if (base.toLowerCase().endsWith("skill.md") &&
|
|
5777
|
+
if (base.toLowerCase().endsWith("skill.md") && existsSync10(base)) {
|
|
5551
5778
|
const dir = dirname8(base);
|
|
5552
|
-
const name2 = directoryBundleName(dir,
|
|
5779
|
+
const name2 = directoryBundleName(dir, basename10(dir));
|
|
5553
5780
|
if (!isKebabCaseName(name2)) {
|
|
5554
5781
|
throw new AuxiliaryError("FILE_DENIED", `Skill directory name must be kebab-case: ${name2}`);
|
|
5555
5782
|
}
|
|
@@ -5557,25 +5784,38 @@ function resolveBundlesFromClone(cloneRoot, subpath) {
|
|
|
5557
5784
|
}
|
|
5558
5785
|
const direct = findSkillBundles(base);
|
|
5559
5786
|
if (direct.length > 0) return direct;
|
|
5560
|
-
for (const rel of ["skills",
|
|
5561
|
-
const nested =
|
|
5787
|
+
for (const rel of ["skills", join19(".agents", "skills"), join19(".dsh", "skills")]) {
|
|
5788
|
+
const nested = join19(base, rel);
|
|
5562
5789
|
const found = findSkillBundles(nested);
|
|
5563
5790
|
if (found.length > 0) return found;
|
|
5564
5791
|
}
|
|
5565
5792
|
throw new AuxiliaryError("FILE_NOT_FOUND", "No SKILL.md bundles found in the repository path");
|
|
5566
5793
|
}
|
|
5567
|
-
function installTargetDir(target, projectRoot, agentsHome) {
|
|
5568
|
-
|
|
5794
|
+
function installTargetDir(target, projectRoot, agentsHome, dshHome2) {
|
|
5795
|
+
switch (target) {
|
|
5796
|
+
case "user":
|
|
5797
|
+
return join19(resolve12(agentsHome), "skills");
|
|
5798
|
+
case "user-dsh":
|
|
5799
|
+
return join19(resolve12(dshHome2), "skills");
|
|
5800
|
+
case "project":
|
|
5801
|
+
return join19(resolve12(projectRoot), ".agents", "skills");
|
|
5802
|
+
case "project-dsh":
|
|
5803
|
+
return join19(resolve12(projectRoot), ".dsh", "skills");
|
|
5804
|
+
default: {
|
|
5805
|
+
const _exhaustive = target;
|
|
5806
|
+
return _exhaustive;
|
|
5807
|
+
}
|
|
5808
|
+
}
|
|
5569
5809
|
}
|
|
5570
5810
|
function destinationForBundle(targetDir, bundle) {
|
|
5571
|
-
return bundle.kind === "directory" ?
|
|
5811
|
+
return bundle.kind === "directory" ? join19(targetDir, bundle.name) : join19(targetDir, `${bundle.name}.md`);
|
|
5572
5812
|
}
|
|
5573
5813
|
function removeDestination(dest) {
|
|
5574
5814
|
removePathRobust(dest);
|
|
5575
5815
|
}
|
|
5576
5816
|
function destinationPresent(path) {
|
|
5577
5817
|
try {
|
|
5578
|
-
|
|
5818
|
+
lstatSync4(path);
|
|
5579
5819
|
return true;
|
|
5580
5820
|
} catch {
|
|
5581
5821
|
return false;
|
|
@@ -5585,25 +5825,67 @@ function isStaleSkillDestination(dest, kind) {
|
|
|
5585
5825
|
if (!destinationPresent(dest)) return false;
|
|
5586
5826
|
if (kind === "file") {
|
|
5587
5827
|
try {
|
|
5588
|
-
const stat =
|
|
5589
|
-
if (stat.isSymbolicLink()) return !
|
|
5828
|
+
const stat = lstatSync4(dest);
|
|
5829
|
+
if (stat.isSymbolicLink()) return !existsSync10(dest);
|
|
5590
5830
|
return !stat.isFile();
|
|
5591
5831
|
} catch {
|
|
5592
5832
|
return true;
|
|
5593
5833
|
}
|
|
5594
5834
|
}
|
|
5595
|
-
return !
|
|
5835
|
+
return !existsSync10(join19(dest, "SKILL.md"));
|
|
5836
|
+
}
|
|
5837
|
+
function copySkillTree(source, dest) {
|
|
5838
|
+
try {
|
|
5839
|
+
cpSync(source, dest, { recursive: true });
|
|
5840
|
+
} catch (error) {
|
|
5841
|
+
if (isWindowsPathBusyError(error)) {
|
|
5842
|
+
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename10(dest)));
|
|
5843
|
+
}
|
|
5844
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
5845
|
+
throw new AuxiliaryError(
|
|
5846
|
+
"FILE_EDIT_FAILED",
|
|
5847
|
+
`Failed to copy skill into ${basename10(dest)}: ${detail.slice(0, 400)}`
|
|
5848
|
+
);
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
function copySkillTreeAtomic(source, dest, kind) {
|
|
5852
|
+
mkdirSync5(dirname8(dest), { recursive: true });
|
|
5853
|
+
if (kind === "file") {
|
|
5854
|
+
if (destinationPresent(dest)) removeDestination(dest);
|
|
5855
|
+
copySkillTree(source, dest);
|
|
5856
|
+
return;
|
|
5857
|
+
}
|
|
5858
|
+
const staging = skillTransientWorkPath("installing", basename10(dest));
|
|
5859
|
+
try {
|
|
5860
|
+
copySkillTree(source, staging);
|
|
5861
|
+
if (destinationPresent(dest)) removeDestination(dest);
|
|
5862
|
+
if (destinationPresent(dest)) {
|
|
5863
|
+
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename10(dest)));
|
|
5864
|
+
}
|
|
5865
|
+
try {
|
|
5866
|
+
renameSync5(staging, dest);
|
|
5867
|
+
} catch (error) {
|
|
5868
|
+
if (isWindowsPathBusyError(error)) {
|
|
5869
|
+
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename10(dest)));
|
|
5870
|
+
}
|
|
5871
|
+
copySkillTree(staging, dest);
|
|
5872
|
+
removeQuietly(staging);
|
|
5873
|
+
}
|
|
5874
|
+
} catch (error) {
|
|
5875
|
+
removeQuietly(staging);
|
|
5876
|
+
throw error;
|
|
5877
|
+
}
|
|
5596
5878
|
}
|
|
5597
|
-
function linkOrCopy(source, dest, mode) {
|
|
5879
|
+
function linkOrCopy(source, dest, mode, kind) {
|
|
5598
5880
|
mkdirSync5(dirname8(dest), { recursive: true });
|
|
5599
5881
|
if (mode === "copy") {
|
|
5600
|
-
|
|
5882
|
+
copySkillTreeAtomic(source, dest, kind);
|
|
5601
5883
|
return "copy";
|
|
5602
5884
|
}
|
|
5603
5885
|
try {
|
|
5604
5886
|
if (process.platform === "win32") {
|
|
5605
|
-
const stat =
|
|
5606
|
-
if (stat.isDirectory() || stat.isSymbolicLink() &&
|
|
5887
|
+
const stat = lstatSync4(source);
|
|
5888
|
+
if (stat.isDirectory() || stat.isSymbolicLink() && existsSync10(join19(source, "SKILL.md"))) {
|
|
5607
5889
|
symlinkSync(source, dest, "junction");
|
|
5608
5890
|
return "link";
|
|
5609
5891
|
}
|
|
@@ -5613,11 +5895,12 @@ function linkOrCopy(source, dest, mode) {
|
|
|
5613
5895
|
symlinkSync(source, dest);
|
|
5614
5896
|
return "link";
|
|
5615
5897
|
} catch {
|
|
5616
|
-
|
|
5898
|
+
copySkillTreeAtomic(source, dest, kind);
|
|
5617
5899
|
return "copy";
|
|
5618
5900
|
}
|
|
5619
5901
|
}
|
|
5620
5902
|
function installBundle(options) {
|
|
5903
|
+
sweepTransientSkillEntries(options.targetDir);
|
|
5621
5904
|
const dest = destinationForBundle(options.targetDir, options.bundle);
|
|
5622
5905
|
if (destinationPresent(dest)) {
|
|
5623
5906
|
if (options.force || isStaleSkillDestination(dest, options.bundle.kind)) {
|
|
@@ -5626,19 +5909,19 @@ function installBundle(options) {
|
|
|
5626
5909
|
throw new AuxiliaryError("FILE_DENIED", `A skill named ${options.bundle.name} already exists`);
|
|
5627
5910
|
}
|
|
5628
5911
|
}
|
|
5629
|
-
const used = linkOrCopy(options.bundle.sourcePath, dest, options.mode);
|
|
5912
|
+
const used = linkOrCopy(options.bundle.sourcePath, dest, options.mode, options.bundle.kind);
|
|
5630
5913
|
return { path: dest, name: options.bundle.name, mode: used };
|
|
5631
5914
|
}
|
|
5632
5915
|
|
|
5633
5916
|
// src/host/instructions-skills/content-revision.ts
|
|
5634
5917
|
import { createHash as createHash7 } from "node:crypto";
|
|
5635
|
-
import { readdirSync as
|
|
5636
|
-
import { join as
|
|
5918
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
5919
|
+
import { join as join20, relative as relative3 } from "node:path";
|
|
5637
5920
|
function listRelativeFiles(dir, root) {
|
|
5638
5921
|
const entries = [];
|
|
5639
|
-
for (const entry of
|
|
5922
|
+
for (const entry of readdirSync6(dir, { withFileTypes: true })) {
|
|
5640
5923
|
if (entry.name.startsWith(".")) continue;
|
|
5641
|
-
const abs =
|
|
5924
|
+
const abs = join20(dir, entry.name);
|
|
5642
5925
|
if (entry.isDirectory()) {
|
|
5643
5926
|
entries.push(...listRelativeFiles(abs, root));
|
|
5644
5927
|
} else if (entry.isFile()) {
|
|
@@ -5651,22 +5934,116 @@ function contentRevisionOfDir(dir) {
|
|
|
5651
5934
|
const paths = listRelativeFiles(dir, dir).sort();
|
|
5652
5935
|
const aggregate = createHash7("sha256");
|
|
5653
5936
|
for (const relPath of paths) {
|
|
5654
|
-
const contents = readFileSync5(
|
|
5937
|
+
const contents = readFileSync5(join20(dir, relPath));
|
|
5655
5938
|
const fileDigest = createHash7("sha256").update(`${relPath}\0`).update(contents).digest();
|
|
5656
5939
|
aggregate.update(fileDigest);
|
|
5657
5940
|
}
|
|
5658
5941
|
return aggregate.digest("hex");
|
|
5659
5942
|
}
|
|
5660
5943
|
|
|
5944
|
+
// src/host/instructions-skills/install-progress.ts
|
|
5945
|
+
var SKILL_INSTALL_STAGES = [
|
|
5946
|
+
"idle",
|
|
5947
|
+
"resolving",
|
|
5948
|
+
"downloading",
|
|
5949
|
+
"extracting",
|
|
5950
|
+
"cloning",
|
|
5951
|
+
"copying",
|
|
5952
|
+
"finishing"
|
|
5953
|
+
];
|
|
5954
|
+
var bySession2 = /* @__PURE__ */ new Map();
|
|
5955
|
+
function idleSnapshot(sessionId) {
|
|
5956
|
+
return {
|
|
5957
|
+
sessionId,
|
|
5958
|
+
stage: "idle",
|
|
5959
|
+
detail: null,
|
|
5960
|
+
bytesReceived: null,
|
|
5961
|
+
bytesTotal: null,
|
|
5962
|
+
startedAt: null
|
|
5963
|
+
};
|
|
5964
|
+
}
|
|
5965
|
+
function snapshotOf(entry) {
|
|
5966
|
+
return {
|
|
5967
|
+
sessionId: entry.sessionId,
|
|
5968
|
+
stage: entry.stage,
|
|
5969
|
+
detail: entry.detail,
|
|
5970
|
+
bytesReceived: entry.bytesReceived,
|
|
5971
|
+
bytesTotal: entry.bytesTotal,
|
|
5972
|
+
startedAt: entry.startedAt
|
|
5973
|
+
};
|
|
5974
|
+
}
|
|
5975
|
+
function beginSkillInstallProgress(sessionId, detail) {
|
|
5976
|
+
const id = sessionId.trim();
|
|
5977
|
+
if (id === "") return;
|
|
5978
|
+
bySession2.set(id, {
|
|
5979
|
+
sessionId: id,
|
|
5980
|
+
stage: "resolving",
|
|
5981
|
+
detail: detail?.trim() || null,
|
|
5982
|
+
bytesReceived: null,
|
|
5983
|
+
bytesTotal: null,
|
|
5984
|
+
startedAt: Date.now()
|
|
5985
|
+
});
|
|
5986
|
+
}
|
|
5987
|
+
function setSkillInstallStage(sessionId, stage, detail) {
|
|
5988
|
+
const id = sessionId.trim();
|
|
5989
|
+
if (id === "") return;
|
|
5990
|
+
const existing = bySession2.get(id);
|
|
5991
|
+
if (existing === void 0) {
|
|
5992
|
+
bySession2.set(id, {
|
|
5993
|
+
sessionId: id,
|
|
5994
|
+
stage,
|
|
5995
|
+
detail: detail?.trim() || null,
|
|
5996
|
+
bytesReceived: null,
|
|
5997
|
+
bytesTotal: null,
|
|
5998
|
+
startedAt: Date.now()
|
|
5999
|
+
});
|
|
6000
|
+
return;
|
|
6001
|
+
}
|
|
6002
|
+
const prev = existing.stage;
|
|
6003
|
+
existing.stage = stage;
|
|
6004
|
+
if (detail !== void 0) {
|
|
6005
|
+
existing.detail = detail?.trim() || null;
|
|
6006
|
+
}
|
|
6007
|
+
if (stage !== "downloading" && stage !== "cloning" || prev !== stage && (stage === "downloading" || stage === "cloning")) {
|
|
6008
|
+
if (stage !== "downloading" && stage !== "cloning") {
|
|
6009
|
+
existing.bytesReceived = null;
|
|
6010
|
+
existing.bytesTotal = null;
|
|
6011
|
+
} else if (prev !== stage) {
|
|
6012
|
+
existing.bytesReceived = null;
|
|
6013
|
+
existing.bytesTotal = null;
|
|
6014
|
+
}
|
|
6015
|
+
}
|
|
6016
|
+
}
|
|
6017
|
+
function setSkillInstallBytes(sessionId, bytesReceived, bytesTotal) {
|
|
6018
|
+
const id = sessionId.trim();
|
|
6019
|
+
if (id === "") return;
|
|
6020
|
+
const existing = bySession2.get(id);
|
|
6021
|
+
if (existing === void 0) return;
|
|
6022
|
+
existing.bytesReceived = Number.isFinite(bytesReceived) ? Math.max(0, bytesReceived) : null;
|
|
6023
|
+
existing.bytesTotal = bytesTotal !== null && Number.isFinite(bytesTotal) && bytesTotal > 0 ? bytesTotal : null;
|
|
6024
|
+
}
|
|
6025
|
+
function clearSkillInstallProgress(sessionId) {
|
|
6026
|
+
const id = sessionId.trim();
|
|
6027
|
+
if (id === "") return;
|
|
6028
|
+
bySession2.delete(id);
|
|
6029
|
+
}
|
|
6030
|
+
function getSkillInstallProgressSnapshot(sessionId) {
|
|
6031
|
+
const id = sessionId.trim();
|
|
6032
|
+
if (id === "") return idleSnapshot("");
|
|
6033
|
+
const existing = bySession2.get(id);
|
|
6034
|
+
if (existing === void 0) return idleSnapshot(id);
|
|
6035
|
+
return snapshotOf(existing);
|
|
6036
|
+
}
|
|
6037
|
+
|
|
5661
6038
|
// src/host/instructions-skills/install.ts
|
|
5662
6039
|
var execFileAsync3 = promisify3(execFile3);
|
|
5663
6040
|
function tempWorkDir(prefix) {
|
|
5664
|
-
let base =
|
|
6041
|
+
let base = tmpdir3();
|
|
5665
6042
|
try {
|
|
5666
6043
|
base = realpathSync(base);
|
|
5667
6044
|
} catch {
|
|
5668
6045
|
}
|
|
5669
|
-
return mkdtempSync(
|
|
6046
|
+
return mkdtempSync(join21(base, prefix));
|
|
5670
6047
|
}
|
|
5671
6048
|
function execDetail(error) {
|
|
5672
6049
|
if (!(error instanceof Error)) return String(error);
|
|
@@ -5683,49 +6060,109 @@ async function assertGitAvailable(signal) {
|
|
|
5683
6060
|
throw new AuxiliaryError("FILE_EDIT_FAILED", "git is not available on PATH");
|
|
5684
6061
|
}
|
|
5685
6062
|
}
|
|
5686
|
-
|
|
6063
|
+
function parseGitClonePercent(chunk) {
|
|
6064
|
+
const match = /(?:Receiving objects|Resolving deltas):\s+(\d+)%/i.exec(chunk);
|
|
6065
|
+
if (match === null) return null;
|
|
6066
|
+
const value = Number(match[1]);
|
|
6067
|
+
return Number.isFinite(value) ? Math.min(100, Math.max(0, value)) : null;
|
|
6068
|
+
}
|
|
6069
|
+
async function shallowClone(cloneUrl, dest, signal, onClonePercent) {
|
|
5687
6070
|
signal.throwIfAborted();
|
|
5688
6071
|
const attempts = 2;
|
|
5689
6072
|
let lastDetail = "";
|
|
5690
6073
|
for (let i = 0; i < attempts; i += 1) {
|
|
5691
6074
|
signal.throwIfAborted();
|
|
5692
6075
|
try {
|
|
5693
|
-
await
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
6076
|
+
await new Promise((resolveClone, rejectClone) => {
|
|
6077
|
+
const child = spawn(
|
|
6078
|
+
"git",
|
|
6079
|
+
[
|
|
6080
|
+
"-c",
|
|
6081
|
+
"http.version=HTTP/1.1",
|
|
6082
|
+
"clone",
|
|
6083
|
+
"--depth",
|
|
6084
|
+
"1",
|
|
6085
|
+
"--progress",
|
|
6086
|
+
"--",
|
|
6087
|
+
cloneUrl,
|
|
6088
|
+
dest
|
|
6089
|
+
],
|
|
6090
|
+
{ windowsHide: true, stdio: ["ignore", "ignore", "pipe"] }
|
|
6091
|
+
);
|
|
6092
|
+
let stderr = "";
|
|
6093
|
+
const onAbort = () => {
|
|
6094
|
+
try {
|
|
6095
|
+
child.kill();
|
|
6096
|
+
} catch {
|
|
6097
|
+
}
|
|
6098
|
+
};
|
|
6099
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
6100
|
+
child.stderr?.setEncoding("utf8");
|
|
6101
|
+
child.stderr?.on("data", (chunk) => {
|
|
6102
|
+
stderr += chunk;
|
|
6103
|
+
if (stderr.length > 8e3) stderr = stderr.slice(-4e3);
|
|
6104
|
+
const percent = parseGitClonePercent(chunk);
|
|
6105
|
+
if (percent !== null) onClonePercent?.(percent);
|
|
6106
|
+
});
|
|
6107
|
+
child.on("error", (error) => {
|
|
6108
|
+
signal.removeEventListener("abort", onAbort);
|
|
6109
|
+
rejectClone(error);
|
|
6110
|
+
});
|
|
6111
|
+
child.on("close", (code) => {
|
|
6112
|
+
signal.removeEventListener("abort", onAbort);
|
|
6113
|
+
if (signal.aborted) {
|
|
6114
|
+
rejectClone(Object.assign(new Error("Aborted"), { name: "AbortError" }));
|
|
6115
|
+
return;
|
|
6116
|
+
}
|
|
6117
|
+
if (code === 0) {
|
|
6118
|
+
resolveClone();
|
|
6119
|
+
return;
|
|
6120
|
+
}
|
|
6121
|
+
rejectClone(new Error(stderr.trim() || `git clone exited ${String(code)}`));
|
|
6122
|
+
});
|
|
6123
|
+
});
|
|
5698
6124
|
signal.throwIfAborted();
|
|
6125
|
+
onClonePercent?.(100);
|
|
5699
6126
|
return;
|
|
5700
6127
|
} catch (error) {
|
|
6128
|
+
if (error instanceof Error && error.name === "AbortError") throw error;
|
|
5701
6129
|
lastDetail = execDetail(error);
|
|
5702
|
-
|
|
6130
|
+
rmSync4(dest, { recursive: true, force: true });
|
|
5703
6131
|
}
|
|
5704
6132
|
}
|
|
5705
6133
|
throw new AuxiliaryError("FILE_EDIT_FAILED", `git clone failed: ${lastDetail}`);
|
|
5706
6134
|
}
|
|
5707
|
-
async function materializeSkillGitTreeFromSource(source, workDir, signal) {
|
|
6135
|
+
async function materializeSkillGitTreeFromSource(source, workDir, signal, progressSessionId) {
|
|
5708
6136
|
const parsed = (() => {
|
|
5709
6137
|
try {
|
|
5710
6138
|
return parseGitSkillSource(source);
|
|
5711
6139
|
} catch (error) {
|
|
5712
6140
|
const detail = error instanceof Error ? error.message : String(error);
|
|
5713
|
-
throw new AuxiliaryError("
|
|
6141
|
+
throw new AuxiliaryError("FILE_EDIT_FAILED", detail);
|
|
5714
6142
|
}
|
|
5715
6143
|
})();
|
|
5716
|
-
const rootDir = await materializeRepo(parsed, workDir, signal);
|
|
6144
|
+
const rootDir = await materializeRepo(parsed, workDir, signal, progressSessionId);
|
|
5717
6145
|
return { rootDir, parsed };
|
|
5718
6146
|
}
|
|
5719
|
-
async function materializeRepo(parsed, workDir, signal) {
|
|
5720
|
-
const cloneDir =
|
|
6147
|
+
async function materializeRepo(parsed, workDir, signal, progressSessionId) {
|
|
6148
|
+
const cloneDir = join21(workDir, "repo");
|
|
5721
6149
|
const archiveErrors = [];
|
|
6150
|
+
const sessionId = progressSessionId?.trim() ?? "";
|
|
5722
6151
|
if (parsed.github !== null) {
|
|
5723
6152
|
try {
|
|
5724
6153
|
return await fetchGithubRepoArchive({
|
|
5725
6154
|
owner: parsed.github.owner,
|
|
5726
6155
|
repo: parsed.github.repo,
|
|
5727
6156
|
workDir,
|
|
5728
|
-
signal
|
|
6157
|
+
signal,
|
|
6158
|
+
onStage: (stage, detail) => {
|
|
6159
|
+
if (sessionId === "") return;
|
|
6160
|
+
setSkillInstallStage(sessionId, stage, detail ?? parsed.label);
|
|
6161
|
+
},
|
|
6162
|
+
onDownloadProgress: (received, total) => {
|
|
6163
|
+
if (sessionId === "") return;
|
|
6164
|
+
setSkillInstallBytes(sessionId, received, total);
|
|
6165
|
+
}
|
|
5729
6166
|
});
|
|
5730
6167
|
} catch (error) {
|
|
5731
6168
|
if (error instanceof Error && error.name === "AbortError") throw error;
|
|
@@ -5733,8 +6170,12 @@ async function materializeRepo(parsed, workDir, signal) {
|
|
|
5733
6170
|
}
|
|
5734
6171
|
}
|
|
5735
6172
|
await assertGitAvailable(signal);
|
|
6173
|
+
if (sessionId !== "") setSkillInstallStage(sessionId, "cloning", parsed.label);
|
|
5736
6174
|
try {
|
|
5737
|
-
await shallowClone(parsed.cloneUrl, cloneDir, signal)
|
|
6175
|
+
await shallowClone(parsed.cloneUrl, cloneDir, signal, (percent) => {
|
|
6176
|
+
if (sessionId === "") return;
|
|
6177
|
+
setSkillInstallBytes(sessionId, percent, 100);
|
|
6178
|
+
});
|
|
5738
6179
|
return cloneDir;
|
|
5739
6180
|
} catch (cloneError) {
|
|
5740
6181
|
const cloneDetail = cloneError instanceof Error ? cloneError.message : String(cloneError);
|
|
@@ -5747,11 +6188,13 @@ async function materializeRepo(parsed, workDir, signal) {
|
|
|
5747
6188
|
}
|
|
5748
6189
|
async function installSkillsFromGit(options) {
|
|
5749
6190
|
const tempRoot = tempWorkDir("ae-skill-git-");
|
|
6191
|
+
const progressSessionId = options.progressSessionId?.trim() ?? "";
|
|
5750
6192
|
try {
|
|
5751
6193
|
const { rootDir: cloneDir, parsed: materialized } = await materializeSkillGitTreeFromSource(
|
|
5752
6194
|
options.source,
|
|
5753
6195
|
tempRoot,
|
|
5754
|
-
options.signal
|
|
6196
|
+
options.signal,
|
|
6197
|
+
progressSessionId === "" ? void 0 : progressSessionId
|
|
5755
6198
|
);
|
|
5756
6199
|
const bundles = resolveBundlesFromClone(cloneDir, materialized.subpath);
|
|
5757
6200
|
if (bundles.length === 0) {
|
|
@@ -5763,63 +6206,94 @@ async function installSkillsFromGit(options) {
|
|
|
5763
6206
|
const targetDir = installTargetDir(
|
|
5764
6207
|
options.target,
|
|
5765
6208
|
options.projectRoot,
|
|
5766
|
-
agentsHomeOf(options.env)
|
|
6209
|
+
agentsHomeOf(options.env),
|
|
6210
|
+
dshHomeOf(options.env)
|
|
5767
6211
|
);
|
|
6212
|
+
if (progressSessionId !== "") {
|
|
6213
|
+
setSkillInstallStage(progressSessionId, "copying", materialized.label);
|
|
6214
|
+
}
|
|
5768
6215
|
const installed = [];
|
|
6216
|
+
const skippedBusy = [];
|
|
5769
6217
|
for (const bundle of bundles) {
|
|
5770
6218
|
options.signal.throwIfAborted();
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
cwd: options.projectRoot,
|
|
5779
|
-
projectRoot: options.projectRoot,
|
|
5780
|
-
env: options.env
|
|
5781
|
-
});
|
|
6219
|
+
try {
|
|
6220
|
+
if (progressSessionId !== "") {
|
|
6221
|
+
setSkillInstallStage(
|
|
6222
|
+
progressSessionId,
|
|
6223
|
+
"copying",
|
|
6224
|
+
`${bundle.name} \xB7 ${installed.length + skippedBusy.length + 1}/${bundles.length}`
|
|
6225
|
+
);
|
|
5782
6226
|
}
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
mode: "copy"
|
|
5789
|
-
});
|
|
5790
|
-
installed.push(result);
|
|
5791
|
-
const ledgerRoot = options.installLedgerRoot?.trim();
|
|
5792
|
-
if (ledgerRoot !== void 0 && ledgerRoot !== "") {
|
|
5793
|
-
upsertInstallRecord(ledgerRoot, {
|
|
5794
|
-
name: result.name,
|
|
5795
|
-
channel: "github",
|
|
5796
|
-
source: options.source.trim(),
|
|
5797
|
-
contentRevision: contentRevisionOfDir(result.path),
|
|
5798
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5799
|
-
updateCheck: true
|
|
6227
|
+
const result = installBundle({
|
|
6228
|
+
bundle,
|
|
6229
|
+
targetDir,
|
|
6230
|
+
force: options.force,
|
|
6231
|
+
mode: "copy"
|
|
5800
6232
|
});
|
|
6233
|
+
installed.push(result);
|
|
6234
|
+
if (options.force) {
|
|
6235
|
+
const folderName = basename11(bundle.sourcePath);
|
|
6236
|
+
const names = /* @__PURE__ */ new Set([bundle.name]);
|
|
6237
|
+
if (isKebabCaseName(folderName)) names.add(folderName);
|
|
6238
|
+
for (const name2 of names) {
|
|
6239
|
+
purgeManagedSkillName({
|
|
6240
|
+
name: name2,
|
|
6241
|
+
cwd: options.projectRoot,
|
|
6242
|
+
projectRoot: options.projectRoot,
|
|
6243
|
+
env: options.env,
|
|
6244
|
+
exceptPaths: name2 === result.name ? [result.path] : []
|
|
6245
|
+
});
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
const ledgerRoot = options.installLedgerRoot?.trim();
|
|
6249
|
+
if (ledgerRoot !== void 0 && ledgerRoot !== "") {
|
|
6250
|
+
upsertInstallRecord(ledgerRoot, {
|
|
6251
|
+
name: result.name,
|
|
6252
|
+
channel: "github",
|
|
6253
|
+
source: options.source.trim(),
|
|
6254
|
+
contentRevision: contentRevisionOfDir(result.path),
|
|
6255
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6256
|
+
updateCheck: true
|
|
6257
|
+
});
|
|
6258
|
+
}
|
|
6259
|
+
} catch (error) {
|
|
6260
|
+
if (isWindowsPathBusyError(error) || error instanceof AuxiliaryError && error.code === "FILE_EDIT_FAILED" && isWindowsPathBusyError(error)) {
|
|
6261
|
+
skippedBusy.push(bundle.name);
|
|
6262
|
+
continue;
|
|
6263
|
+
}
|
|
6264
|
+
if (error instanceof AuxiliaryError && error.code === "FILE_EDIT_FAILED" && /still present|file in use|EPERM|EIO/i.test(error.message)) {
|
|
6265
|
+
skippedBusy.push(bundle.name);
|
|
6266
|
+
continue;
|
|
6267
|
+
}
|
|
6268
|
+
throw error;
|
|
5801
6269
|
}
|
|
5802
6270
|
}
|
|
5803
|
-
|
|
6271
|
+
if (installed.length === 0 && skippedBusy.length > 0) {
|
|
6272
|
+
throw new AuxiliaryError(
|
|
6273
|
+
"FILE_EDIT_FAILED",
|
|
6274
|
+
`Failed to update ${skippedBusy[0]}: still present (EPERM / EIO / file in use \u2014 close skill preview or Desktop file tabs, then retry)`
|
|
6275
|
+
);
|
|
6276
|
+
}
|
|
6277
|
+
return { installed, skippedBusy };
|
|
5804
6278
|
} finally {
|
|
5805
6279
|
try {
|
|
5806
|
-
|
|
6280
|
+
rmSync4(tempRoot, { recursive: true, force: true });
|
|
5807
6281
|
} catch {
|
|
5808
6282
|
}
|
|
5809
6283
|
}
|
|
5810
6284
|
}
|
|
5811
6285
|
|
|
5812
6286
|
// src/host/instructions-skills/update-check.ts
|
|
5813
|
-
import { mkdtempSync as mkdtempSync2, realpathSync as realpathSync2, rmSync as
|
|
5814
|
-
import { tmpdir as
|
|
5815
|
-
import { join as
|
|
6287
|
+
import { mkdtempSync as mkdtempSync2, realpathSync as realpathSync2, rmSync as rmSync5 } from "node:fs";
|
|
6288
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
6289
|
+
import { join as join22 } from "node:path";
|
|
5816
6290
|
function tempWorkDir2(prefix) {
|
|
5817
|
-
let base =
|
|
6291
|
+
let base = tmpdir4();
|
|
5818
6292
|
try {
|
|
5819
6293
|
base = realpathSync2(base);
|
|
5820
6294
|
} catch {
|
|
5821
6295
|
}
|
|
5822
|
-
return mkdtempSync2(
|
|
6296
|
+
return mkdtempSync2(join22(base, prefix));
|
|
5823
6297
|
}
|
|
5824
6298
|
function revisionPathForBundle(bundle) {
|
|
5825
6299
|
return bundle.kind === "directory" ? bundle.sourcePath : bundle.sourcePath;
|
|
@@ -5870,7 +6344,7 @@ async function checkGithubSkillUpdate(record2, options) {
|
|
|
5870
6344
|
return noUpdate(label, true);
|
|
5871
6345
|
} finally {
|
|
5872
6346
|
try {
|
|
5873
|
-
|
|
6347
|
+
rmSync5(tempRoot, { recursive: true, force: true });
|
|
5874
6348
|
} catch {
|
|
5875
6349
|
}
|
|
5876
6350
|
}
|
|
@@ -5878,18 +6352,18 @@ async function checkGithubSkillUpdate(record2, options) {
|
|
|
5878
6352
|
|
|
5879
6353
|
// src/host/instructions-skills/zip-install.ts
|
|
5880
6354
|
import { execFile as execFile4 } from "node:child_process";
|
|
5881
|
-
import { existsSync as
|
|
5882
|
-
import { tmpdir as
|
|
5883
|
-
import { basename as
|
|
6355
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync6, mkdtempSync as mkdtempSync3, realpathSync as realpathSync3, rmSync as rmSync6 } from "node:fs";
|
|
6356
|
+
import { tmpdir as tmpdir5 } from "node:os";
|
|
6357
|
+
import { basename as basename12, join as join23, resolve as resolve14 } from "node:path";
|
|
5884
6358
|
import { promisify as promisify4 } from "node:util";
|
|
5885
6359
|
var execFileAsync4 = promisify4(execFile4);
|
|
5886
6360
|
function tempWorkDir3(prefix) {
|
|
5887
|
-
let base =
|
|
6361
|
+
let base = tmpdir5();
|
|
5888
6362
|
try {
|
|
5889
6363
|
base = realpathSync3(base);
|
|
5890
6364
|
} catch {
|
|
5891
6365
|
}
|
|
5892
|
-
return mkdtempSync3(
|
|
6366
|
+
return mkdtempSync3(join23(base, prefix));
|
|
5893
6367
|
}
|
|
5894
6368
|
async function extractZipArchive(zipPath, destDir, signal) {
|
|
5895
6369
|
signal.throwIfAborted();
|
|
@@ -5906,15 +6380,15 @@ async function extractZipArchive(zipPath, destDir, signal) {
|
|
|
5906
6380
|
signal.throwIfAborted();
|
|
5907
6381
|
}
|
|
5908
6382
|
async function installSkillsFromZipFile(options) {
|
|
5909
|
-
const zipPath =
|
|
5910
|
-
if (!
|
|
6383
|
+
const zipPath = resolve14(options.zipPath);
|
|
6384
|
+
if (!existsSync12(zipPath)) {
|
|
5911
6385
|
throw new AuxiliaryError("FILE_NOT_FOUND", `Zip not found: ${zipPath}`);
|
|
5912
6386
|
}
|
|
5913
6387
|
if (!zipPath.toLowerCase().endsWith(".zip")) {
|
|
5914
|
-
throw new AuxiliaryError("FILE_DENIED", `Expected a .zip archive: ${
|
|
6388
|
+
throw new AuxiliaryError("FILE_DENIED", `Expected a .zip archive: ${basename12(zipPath)}`);
|
|
5915
6389
|
}
|
|
5916
6390
|
const workDir = tempWorkDir3("ae-skill-zip-");
|
|
5917
|
-
const extractDir =
|
|
6391
|
+
const extractDir = join23(workDir, "extract");
|
|
5918
6392
|
try {
|
|
5919
6393
|
await extractZipArchive(zipPath, extractDir, options.signal);
|
|
5920
6394
|
const root = unwrapArchiveRoot(extractDir);
|
|
@@ -5928,13 +6402,21 @@ async function installSkillsFromZipFile(options) {
|
|
|
5928
6402
|
const targetDir = installTargetDir(
|
|
5929
6403
|
options.target,
|
|
5930
6404
|
options.projectRoot,
|
|
5931
|
-
agentsHomeOf(options.env)
|
|
6405
|
+
agentsHomeOf(options.env),
|
|
6406
|
+
dshHomeOf(options.env)
|
|
5932
6407
|
);
|
|
5933
6408
|
const installed = [];
|
|
5934
6409
|
for (const bundle of bundles) {
|
|
5935
6410
|
options.signal.throwIfAborted();
|
|
6411
|
+
const result = installBundle({
|
|
6412
|
+
bundle,
|
|
6413
|
+
targetDir,
|
|
6414
|
+
force: options.force,
|
|
6415
|
+
mode: "copy"
|
|
6416
|
+
});
|
|
6417
|
+
installed.push(result);
|
|
5936
6418
|
if (options.force) {
|
|
5937
|
-
const folderName =
|
|
6419
|
+
const folderName = basename12(bundle.sourcePath);
|
|
5938
6420
|
const names = /* @__PURE__ */ new Set([bundle.name]);
|
|
5939
6421
|
if (isKebabCaseName(folderName)) names.add(folderName);
|
|
5940
6422
|
for (const name2 of names) {
|
|
@@ -5942,17 +6424,11 @@ async function installSkillsFromZipFile(options) {
|
|
|
5942
6424
|
name: name2,
|
|
5943
6425
|
cwd: options.projectRoot,
|
|
5944
6426
|
projectRoot: options.projectRoot,
|
|
5945
|
-
env: options.env
|
|
6427
|
+
env: options.env,
|
|
6428
|
+
exceptPaths: name2 === result.name ? [result.path] : []
|
|
5946
6429
|
});
|
|
5947
6430
|
}
|
|
5948
6431
|
}
|
|
5949
|
-
const result = installBundle({
|
|
5950
|
-
bundle,
|
|
5951
|
-
targetDir,
|
|
5952
|
-
force: options.force,
|
|
5953
|
-
mode: "copy"
|
|
5954
|
-
});
|
|
5955
|
-
installed.push(result);
|
|
5956
6432
|
const ledgerRoot = options.installLedgerRoot?.trim();
|
|
5957
6433
|
if (ledgerRoot !== void 0 && ledgerRoot !== "") {
|
|
5958
6434
|
upsertInstallRecord(ledgerRoot, {
|
|
@@ -5968,7 +6444,7 @@ async function installSkillsFromZipFile(options) {
|
|
|
5968
6444
|
return installed;
|
|
5969
6445
|
} finally {
|
|
5970
6446
|
try {
|
|
5971
|
-
|
|
6447
|
+
rmSync6(workDir, { recursive: true, force: true });
|
|
5972
6448
|
} catch {
|
|
5973
6449
|
}
|
|
5974
6450
|
}
|
|
@@ -5977,11 +6453,11 @@ async function installSkillsFromZipFile(options) {
|
|
|
5977
6453
|
// src/host/instructions-skills/io.ts
|
|
5978
6454
|
function sessionCwd3(session) {
|
|
5979
6455
|
const header = session?.header;
|
|
5980
|
-
if (typeof header?.cwd === "string" && header.cwd.trim() !== "") return
|
|
6456
|
+
if (typeof header?.cwd === "string" && header.cwd.trim() !== "") return resolve15(header.cwd);
|
|
5981
6457
|
try {
|
|
5982
6458
|
const requested = session?.requestHeader?.();
|
|
5983
6459
|
if (typeof requested?.cwd === "string" && requested.cwd.trim() !== "") {
|
|
5984
|
-
return
|
|
6460
|
+
return resolve15(requested.cwd);
|
|
5985
6461
|
}
|
|
5986
6462
|
} catch {
|
|
5987
6463
|
}
|
|
@@ -6037,6 +6513,7 @@ async function enrichSkillsFromLedger(skills, options) {
|
|
|
6037
6513
|
return skills.map((skill) => ({ ...defaultSkillInstallMeta(), ...skill }));
|
|
6038
6514
|
}
|
|
6039
6515
|
const ledger = readInstallLedger(ledgerRoot);
|
|
6516
|
+
const checkUpdates = options.checkUpdates === true;
|
|
6040
6517
|
const out = [];
|
|
6041
6518
|
for (const skill of skills) {
|
|
6042
6519
|
const record2 = ledger[skill.name];
|
|
@@ -6050,7 +6527,7 @@ async function enrichSkillsFromLedger(skills, options) {
|
|
|
6050
6527
|
installChannel: record2.channel,
|
|
6051
6528
|
updateSourceLabel: ledgerSourceLabel(record2.source)
|
|
6052
6529
|
};
|
|
6053
|
-
if (record2.channel === "github" && record2.updateCheck) {
|
|
6530
|
+
if (checkUpdates && record2.channel === "github" && record2.updateCheck) {
|
|
6054
6531
|
try {
|
|
6055
6532
|
const check = await checkGithubSkillUpdate(record2, { signal: options.signal });
|
|
6056
6533
|
entry = {
|
|
@@ -6074,13 +6551,24 @@ async function enrichSkillsFromLedger(skills, options) {
|
|
|
6074
6551
|
}
|
|
6075
6552
|
function inferSkillInstallTarget(name2, cwd, projectRoot, env = process.env) {
|
|
6076
6553
|
const roots = skillRootsFor(cwd, projectRoot, env);
|
|
6077
|
-
const projectAgents =
|
|
6078
|
-
const projectDsh =
|
|
6554
|
+
const projectAgents = join24(resolve15(projectRoot), ".agents", "skills");
|
|
6555
|
+
const projectDsh = join24(resolve15(projectRoot), ".dsh", "skills");
|
|
6556
|
+
const userAgents = join24(agentsHomeOf(env), "skills");
|
|
6557
|
+
const userDsh = join24(dshHomeOf(env), "skills");
|
|
6079
6558
|
for (const root of roots) {
|
|
6080
|
-
const present =
|
|
6559
|
+
const present = existsSync13(join24(root, name2, "SKILL.md")) || existsSync13(join24(root, `${name2}.md`));
|
|
6081
6560
|
if (!present) continue;
|
|
6082
|
-
if (samePath2(root, projectAgents)
|
|
6083
|
-
return "
|
|
6561
|
+
if (samePath2(root, projectAgents)) return "project";
|
|
6562
|
+
if (samePath2(root, projectDsh)) return "project-dsh";
|
|
6563
|
+
if (samePath2(root, userAgents)) return "user";
|
|
6564
|
+
if (samePath2(root, userDsh)) return "user-dsh";
|
|
6565
|
+
const normalized = root.toLowerCase().split(/[/\\]/).join(sep7);
|
|
6566
|
+
const dshMarker = `${sep7}.dsh${sep7}skills`;
|
|
6567
|
+
const underProject = isInsideOrSame(resolve15(projectRoot), root);
|
|
6568
|
+
if (normalized.includes(dshMarker) || normalized.endsWith(`${sep7}.dsh${sep7}skills`)) {
|
|
6569
|
+
return underProject ? "project-dsh" : "user-dsh";
|
|
6570
|
+
}
|
|
6571
|
+
return underProject ? "project" : "user";
|
|
6084
6572
|
}
|
|
6085
6573
|
throw new AuxiliaryError("FILE_NOT_FOUND", `Skill is not installed in a managed skills root: ${name2}`);
|
|
6086
6574
|
}
|
|
@@ -6098,7 +6586,8 @@ async function buildSnapshot(ctx, sessionId, cwd, options) {
|
|
|
6098
6586
|
const signal = options?.signal ?? new AbortController().signal;
|
|
6099
6587
|
const skills = await enrichSkillsFromLedger(merged.skills, {
|
|
6100
6588
|
installLedgerRoot: options?.installLedgerRoot,
|
|
6101
|
-
signal
|
|
6589
|
+
signal,
|
|
6590
|
+
checkUpdates: options?.checkUpdates === true
|
|
6102
6591
|
});
|
|
6103
6592
|
return {
|
|
6104
6593
|
sessionId,
|
|
@@ -6116,7 +6605,8 @@ async function listInstructionsSkillsNow(options) {
|
|
|
6116
6605
|
options.signal.throwIfAborted();
|
|
6117
6606
|
return buildSnapshot(options.ctx, options.request.sessionId, cwd, {
|
|
6118
6607
|
installLedgerRoot: options.installLedgerRoot,
|
|
6119
|
-
signal: options.signal
|
|
6608
|
+
signal: options.signal,
|
|
6609
|
+
checkUpdates: options.request.checkUpdates === true
|
|
6120
6610
|
});
|
|
6121
6611
|
}
|
|
6122
6612
|
async function createWorkspaceAgentsNow(options) {
|
|
@@ -6147,24 +6637,36 @@ async function createWorkspaceSkillNow(options) {
|
|
|
6147
6637
|
}
|
|
6148
6638
|
async function installSkillFromGitNow(options) {
|
|
6149
6639
|
options.signal.throwIfAborted();
|
|
6150
|
-
const
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6640
|
+
const sessionId = String(options.request.sessionId);
|
|
6641
|
+
beginSkillInstallProgress(sessionId, options.request.source);
|
|
6642
|
+
try {
|
|
6643
|
+
const agent = agentOf2(options.ctx, options.request.sessionId);
|
|
6644
|
+
const cwd = sessionCwd3(agent.session);
|
|
6645
|
+
const discovered = discoverInstructionFiles({ cwd });
|
|
6646
|
+
const batch = await installSkillsFromGit({
|
|
6647
|
+
source: options.request.source,
|
|
6648
|
+
target: options.request.target,
|
|
6649
|
+
projectRoot: discovered.projectRoot,
|
|
6650
|
+
// Panel installs overwrite by default; pass force: false to refuse collisions.
|
|
6651
|
+
force: options.request.force !== false,
|
|
6652
|
+
signal: options.signal,
|
|
6653
|
+
installLedgerRoot: options.installLedgerRoot,
|
|
6654
|
+
progressSessionId: sessionId
|
|
6655
|
+
});
|
|
6656
|
+
options.signal.throwIfAborted();
|
|
6657
|
+
setSkillInstallStage(sessionId, "finishing", options.request.source);
|
|
6658
|
+
const snapshot = await buildSnapshot(options.ctx, options.request.sessionId, cwd, {
|
|
6659
|
+
installLedgerRoot: options.installLedgerRoot,
|
|
6660
|
+
signal: options.signal
|
|
6661
|
+
});
|
|
6662
|
+
return {
|
|
6663
|
+
installed: batch.installed,
|
|
6664
|
+
skippedBusy: batch.skippedBusy,
|
|
6665
|
+
snapshot
|
|
6666
|
+
};
|
|
6667
|
+
} finally {
|
|
6668
|
+
clearSkillInstallProgress(sessionId);
|
|
6669
|
+
}
|
|
6168
6670
|
}
|
|
6169
6671
|
async function installSkillFromZipNow(options) {
|
|
6170
6672
|
options.signal.throwIfAborted();
|
|
@@ -6235,40 +6737,48 @@ async function updateSkillFromGitNow(options) {
|
|
|
6235
6737
|
if (source === "") {
|
|
6236
6738
|
throw new AuxiliaryError("FILE_DENIED", "Install record is missing a git source");
|
|
6237
6739
|
}
|
|
6238
|
-
const
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
cwd
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
target,
|
|
6249
|
-
projectRoot: discovered.projectRoot,
|
|
6250
|
-
force: true,
|
|
6251
|
-
signal: options.signal,
|
|
6252
|
-
installLedgerRoot: ledgerRoot
|
|
6253
|
-
});
|
|
6254
|
-
options.signal.throwIfAborted();
|
|
6255
|
-
const updated = installed.find((entry) => entry.name === options.request.name);
|
|
6256
|
-
if (updated === void 0) {
|
|
6257
|
-
throw new AuxiliaryError(
|
|
6258
|
-
"FILE_NOT_FOUND",
|
|
6259
|
-
`Skill ${options.request.name} was not present in the git source`
|
|
6740
|
+
const sessionId = String(options.request.sessionId);
|
|
6741
|
+
beginSkillInstallProgress(sessionId, source);
|
|
6742
|
+
try {
|
|
6743
|
+
const agent = agentOf2(options.ctx, options.request.sessionId);
|
|
6744
|
+
const cwd = sessionCwd3(agent.session);
|
|
6745
|
+
const discovered = discoverInstructionFiles({ cwd });
|
|
6746
|
+
const target = inferSkillInstallTarget(
|
|
6747
|
+
options.request.name,
|
|
6748
|
+
cwd,
|
|
6749
|
+
discovered.projectRoot
|
|
6260
6750
|
);
|
|
6751
|
+
const batch = await installSkillsFromGit({
|
|
6752
|
+
source,
|
|
6753
|
+
target,
|
|
6754
|
+
projectRoot: discovered.projectRoot,
|
|
6755
|
+
force: true,
|
|
6756
|
+
signal: options.signal,
|
|
6757
|
+
installLedgerRoot: ledgerRoot,
|
|
6758
|
+
progressSessionId: sessionId
|
|
6759
|
+
});
|
|
6760
|
+
options.signal.throwIfAborted();
|
|
6761
|
+
const updated = batch.installed.find((entry) => entry.name === options.request.name);
|
|
6762
|
+
if (updated === void 0) {
|
|
6763
|
+
throw new AuxiliaryError(
|
|
6764
|
+
"FILE_NOT_FOUND",
|
|
6765
|
+
`Skill ${options.request.name} was not present in the git source`
|
|
6766
|
+
);
|
|
6767
|
+
}
|
|
6768
|
+
setSkillInstallStage(sessionId, "finishing", source);
|
|
6769
|
+
const snapshot = await buildSnapshot(options.ctx, options.request.sessionId, cwd, {
|
|
6770
|
+
installLedgerRoot: ledgerRoot,
|
|
6771
|
+
signal: options.signal
|
|
6772
|
+
});
|
|
6773
|
+
return { updated, snapshot };
|
|
6774
|
+
} finally {
|
|
6775
|
+
clearSkillInstallProgress(sessionId);
|
|
6261
6776
|
}
|
|
6262
|
-
const snapshot = await buildSnapshot(options.ctx, options.request.sessionId, cwd, {
|
|
6263
|
-
installLedgerRoot: ledgerRoot,
|
|
6264
|
-
signal: options.signal
|
|
6265
|
-
});
|
|
6266
|
-
return { updated, snapshot };
|
|
6267
6777
|
}
|
|
6268
6778
|
function skillDocumentAbsolutePath(path) {
|
|
6269
6779
|
const trimmed = path.replace(/[/\\]+$/, "");
|
|
6270
|
-
if (/\.md$/i.test(trimmed)) return
|
|
6271
|
-
return
|
|
6780
|
+
if (/\.md$/i.test(trimmed)) return resolve15(trimmed);
|
|
6781
|
+
return resolve15(trimmed, "SKILL.md");
|
|
6272
6782
|
}
|
|
6273
6783
|
async function readSkillDocumentNow(options) {
|
|
6274
6784
|
options.signal.throwIfAborted();
|
|
@@ -6280,11 +6790,11 @@ async function readSkillDocumentNow(options) {
|
|
|
6280
6790
|
if (!roots.some((root) => isInsideOrSame(root, absolutePath2))) {
|
|
6281
6791
|
throw new AuxiliaryError("FILE_DENIED", "Skill document is outside preview roots");
|
|
6282
6792
|
}
|
|
6283
|
-
if (
|
|
6793
|
+
if (basename13(absolutePath2).toLowerCase() !== "skill.md") {
|
|
6284
6794
|
throw new AuxiliaryError("FILE_DENIED", "Only SKILL.md may be previewed");
|
|
6285
6795
|
}
|
|
6286
6796
|
options.signal.throwIfAborted();
|
|
6287
|
-
if (!
|
|
6797
|
+
if (!existsSync13(absolutePath2)) {
|
|
6288
6798
|
throw new AuxiliaryError("FILE_NOT_FOUND", "Skill document not found");
|
|
6289
6799
|
}
|
|
6290
6800
|
try {
|
|
@@ -6319,7 +6829,7 @@ async function readSkillDocumentNow(options) {
|
|
|
6319
6829
|
}
|
|
6320
6830
|
|
|
6321
6831
|
// src/host/mcp-connectors/io.ts
|
|
6322
|
-
import { existsSync as
|
|
6832
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
6323
6833
|
|
|
6324
6834
|
// src/host/mcp-connectors/validate.ts
|
|
6325
6835
|
var MCP_SERVER_NAME_PATTERN = /^[A-Za-z0-9_-]{1,32}$/;
|
|
@@ -6441,22 +6951,22 @@ function parseMcpJsonText(jsonText) {
|
|
|
6441
6951
|
}
|
|
6442
6952
|
|
|
6443
6953
|
// src/host/mcp-connectors/install-git.ts
|
|
6444
|
-
import { existsSync as
|
|
6445
|
-
import { join as
|
|
6954
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync7, readFileSync as readFileSync7, renameSync as renameSync6, rmSync as rmSync7 } from "node:fs";
|
|
6955
|
+
import { join as join26 } from "node:path";
|
|
6446
6956
|
|
|
6447
6957
|
// src/host/mcp-connectors/paths.ts
|
|
6448
|
-
import { join as
|
|
6958
|
+
import { join as join25 } from "node:path";
|
|
6449
6959
|
function mcpConnectorsRoot(pluginDataPackageRoot) {
|
|
6450
|
-
return
|
|
6960
|
+
return join25(pluginDataPackageRoot, "mcp-connectors");
|
|
6451
6961
|
}
|
|
6452
6962
|
function mcpConnectorsLedgerPath(root) {
|
|
6453
|
-
return
|
|
6963
|
+
return join25(root, "mcp-connectors.json");
|
|
6454
6964
|
}
|
|
6455
6965
|
function mcpServersRoot(root) {
|
|
6456
|
-
return
|
|
6966
|
+
return join25(root, "mcp-servers");
|
|
6457
6967
|
}
|
|
6458
6968
|
function mcpServerInstallDir(root, id) {
|
|
6459
|
-
return
|
|
6969
|
+
return join25(mcpServersRoot(root), id);
|
|
6460
6970
|
}
|
|
6461
6971
|
|
|
6462
6972
|
// src/host/mcp-connectors/install-git.ts
|
|
@@ -6473,8 +6983,8 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
6473
6983
|
cwd: installDir
|
|
6474
6984
|
};
|
|
6475
6985
|
}
|
|
6476
|
-
const pkgPath =
|
|
6477
|
-
if (!
|
|
6986
|
+
const pkgPath = join26(installDir, "package.json");
|
|
6987
|
+
if (!existsSync14(pkgPath)) {
|
|
6478
6988
|
return {
|
|
6479
6989
|
transport: "stdio",
|
|
6480
6990
|
command: "npx",
|
|
@@ -6491,7 +7001,7 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
6491
7001
|
return {
|
|
6492
7002
|
transport: "stdio",
|
|
6493
7003
|
command: process.execPath,
|
|
6494
|
-
args: [
|
|
7004
|
+
args: [join26(installDir, bin)],
|
|
6495
7005
|
env: {},
|
|
6496
7006
|
cwd: installDir
|
|
6497
7007
|
};
|
|
@@ -6504,7 +7014,7 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
6504
7014
|
return {
|
|
6505
7015
|
transport: "stdio",
|
|
6506
7016
|
command: process.execPath,
|
|
6507
|
-
args: [
|
|
7017
|
+
args: [join26(installDir, first)],
|
|
6508
7018
|
env: {},
|
|
6509
7019
|
cwd: installDir
|
|
6510
7020
|
};
|
|
@@ -6514,7 +7024,7 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
6514
7024
|
return {
|
|
6515
7025
|
transport: "stdio",
|
|
6516
7026
|
command: process.execPath,
|
|
6517
|
-
args: [
|
|
7027
|
+
args: [join26(installDir, pkg.main)],
|
|
6518
7028
|
env: {},
|
|
6519
7029
|
cwd: installDir
|
|
6520
7030
|
};
|
|
@@ -6533,16 +7043,16 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
6533
7043
|
async function installMcpServerFromGit(options) {
|
|
6534
7044
|
const parsed = parseGitSkillSource(options.source);
|
|
6535
7045
|
const installDir = mcpServerInstallDir(options.rootDir, options.id);
|
|
6536
|
-
if (
|
|
7046
|
+
if (existsSync14(installDir)) {
|
|
6537
7047
|
if (!options.force) {
|
|
6538
7048
|
throw new AuxiliaryError("FILE_EDIT_FAILED", `MCP install dir already exists: ${installDir}`);
|
|
6539
7049
|
}
|
|
6540
7050
|
removePathRobust(installDir);
|
|
6541
7051
|
}
|
|
6542
|
-
mkdirSync7(
|
|
7052
|
+
mkdirSync7(join26(options.rootDir, "mcp-servers"), { recursive: true });
|
|
6543
7053
|
const staging = `${installDir}.staging.${process.pid}`;
|
|
6544
7054
|
try {
|
|
6545
|
-
if (
|
|
7055
|
+
if (existsSync14(staging)) removePathRobust(staging);
|
|
6546
7056
|
mkdirSync7(staging, { recursive: true });
|
|
6547
7057
|
if (parsed.github === null) {
|
|
6548
7058
|
throw new AuxiliaryError(
|
|
@@ -6559,20 +7069,20 @@ async function installMcpServerFromGit(options) {
|
|
|
6559
7069
|
options.signal.throwIfAborted();
|
|
6560
7070
|
let contentRoot = repoDir;
|
|
6561
7071
|
if (parsed.subpath !== null) {
|
|
6562
|
-
const nested =
|
|
6563
|
-
if (!
|
|
7072
|
+
const nested = join26(repoDir, parsed.subpath);
|
|
7073
|
+
if (!existsSync14(nested)) {
|
|
6564
7074
|
throw new AuxiliaryError("FILE_EDIT_FAILED", `Subpath not found in repo: ${parsed.subpath}`);
|
|
6565
7075
|
}
|
|
6566
7076
|
contentRoot = nested;
|
|
6567
7077
|
}
|
|
6568
|
-
mkdirSync7(
|
|
7078
|
+
mkdirSync7(join26(options.rootDir, "mcp-servers"), { recursive: true });
|
|
6569
7079
|
if (contentRoot !== repoDir) {
|
|
6570
7080
|
const nestedStaging = `${installDir}.nested.${process.pid}`;
|
|
6571
|
-
|
|
7081
|
+
renameSync6(contentRoot, nestedStaging);
|
|
6572
7082
|
removePathRobust(staging);
|
|
6573
|
-
|
|
7083
|
+
renameSync6(nestedStaging, installDir);
|
|
6574
7084
|
} else {
|
|
6575
|
-
|
|
7085
|
+
renameSync6(repoDir, installDir);
|
|
6576
7086
|
try {
|
|
6577
7087
|
removePathRobust(staging);
|
|
6578
7088
|
} catch {
|
|
@@ -6580,11 +7090,11 @@ async function installMcpServerFromGit(options) {
|
|
|
6580
7090
|
}
|
|
6581
7091
|
} catch (error) {
|
|
6582
7092
|
try {
|
|
6583
|
-
if (
|
|
7093
|
+
if (existsSync14(staging)) rmSync7(staging, { recursive: true, force: true });
|
|
6584
7094
|
} catch {
|
|
6585
7095
|
}
|
|
6586
7096
|
try {
|
|
6587
|
-
if (
|
|
7097
|
+
if (existsSync14(installDir)) removePathRobust(installDir);
|
|
6588
7098
|
} catch {
|
|
6589
7099
|
}
|
|
6590
7100
|
if (error instanceof AuxiliaryError) throw error;
|
|
@@ -6599,7 +7109,7 @@ async function installMcpServerFromGit(options) {
|
|
|
6599
7109
|
}
|
|
6600
7110
|
|
|
6601
7111
|
// src/host/mcp-connectors/io.ts
|
|
6602
|
-
function
|
|
7112
|
+
function snapshotOf2(host) {
|
|
6603
7113
|
return {
|
|
6604
7114
|
connectors: host.store.load().connectors,
|
|
6605
7115
|
bridgeAvailable: host.runtime.bridgeAvailable,
|
|
@@ -6614,12 +7124,12 @@ function findByServerName(connectors, serverName, exceptId) {
|
|
|
6614
7124
|
async function persistAndSync(host, connectors) {
|
|
6615
7125
|
host.store.save(connectors);
|
|
6616
7126
|
await host.runtime.sync();
|
|
6617
|
-
return
|
|
7127
|
+
return snapshotOf2(host);
|
|
6618
7128
|
}
|
|
6619
7129
|
async function listMcpConnectorsNow(host) {
|
|
6620
7130
|
await host.runtime.ensureBridge();
|
|
6621
7131
|
await host.runtime.sync();
|
|
6622
|
-
return
|
|
7132
|
+
return snapshotOf2(host);
|
|
6623
7133
|
}
|
|
6624
7134
|
async function upsertMcpConnectorNow(host, request) {
|
|
6625
7135
|
const serverName = assertServerName(request.serverName);
|
|
@@ -6682,7 +7192,7 @@ async function uninstallMcpConnectorNow(host, request) {
|
|
|
6682
7192
|
}
|
|
6683
7193
|
const next = doc.connectors.filter((entry) => entry.id !== request.id);
|
|
6684
7194
|
const installDir = mcpServerInstallDir(host.store.rootDir, request.id);
|
|
6685
|
-
if (
|
|
7195
|
+
if (existsSync15(installDir)) {
|
|
6686
7196
|
try {
|
|
6687
7197
|
removePathRobust(installDir);
|
|
6688
7198
|
} catch (error) {
|
|
@@ -6793,7 +7303,7 @@ async function importMcpJsonNow(host, request) {
|
|
|
6793
7303
|
return {
|
|
6794
7304
|
imported,
|
|
6795
7305
|
skipped,
|
|
6796
|
-
snapshot:
|
|
7306
|
+
snapshot: snapshotOf2(host)
|
|
6797
7307
|
};
|
|
6798
7308
|
}
|
|
6799
7309
|
function listMcpConnectorToolsNow(host, request) {
|
|
@@ -6814,7 +7324,7 @@ function listMcpConnectorToolsNow(host, request) {
|
|
|
6814
7324
|
}
|
|
6815
7325
|
|
|
6816
7326
|
// src/host/mcp-connectors/store.ts
|
|
6817
|
-
import { mkdirSync as mkdirSync8, readFileSync as readFileSync8, renameSync as
|
|
7327
|
+
import { mkdirSync as mkdirSync8, readFileSync as readFileSync8, renameSync as renameSync7, writeFileSync as writeFileSync4 } from "node:fs";
|
|
6818
7328
|
import { dirname as dirname10 } from "node:path";
|
|
6819
7329
|
|
|
6820
7330
|
// src/host/mcp-connectors/types.ts
|
|
@@ -6920,7 +7430,7 @@ function createMcpConnectorsStore(rootDir) {
|
|
|
6920
7430
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
6921
7431
|
writeFileSync4(tmp, `${JSON.stringify(doc, null, 2)}
|
|
6922
7432
|
`, "utf8");
|
|
6923
|
-
|
|
7433
|
+
renameSync7(tmp, file);
|
|
6924
7434
|
return doc;
|
|
6925
7435
|
}
|
|
6926
7436
|
};
|
|
@@ -7602,7 +8112,7 @@ var SoftPauseGate = class {
|
|
|
7602
8112
|
this.clear(sessionId);
|
|
7603
8113
|
return;
|
|
7604
8114
|
}
|
|
7605
|
-
await new Promise((
|
|
8115
|
+
await new Promise((resolve16) => {
|
|
7606
8116
|
let settled = false;
|
|
7607
8117
|
const settle = () => {
|
|
7608
8118
|
if (settled) return;
|
|
@@ -7613,7 +8123,7 @@ var SoftPauseGate = class {
|
|
|
7613
8123
|
bucket2.delete(waiter);
|
|
7614
8124
|
if (bucket2.size === 0) this.waiters.delete(sessionId);
|
|
7615
8125
|
}
|
|
7616
|
-
|
|
8126
|
+
resolve16();
|
|
7617
8127
|
};
|
|
7618
8128
|
const onAbort = () => {
|
|
7619
8129
|
this.engaged.delete(sessionId);
|
|
@@ -8827,7 +9337,7 @@ function mergeUsageCalls(stored, history) {
|
|
|
8827
9337
|
// src/host/usage/ledger.ts
|
|
8828
9338
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
8829
9339
|
import { chmod as chmod4, mkdir as mkdir5, readFile as readFile5, rename as rename4, unlink as unlink5, writeFile as writeFile4 } from "node:fs/promises";
|
|
8830
|
-
import { basename as
|
|
9340
|
+
import { basename as basename14, join as join27 } from "node:path";
|
|
8831
9341
|
import { z as z3 } from "zod";
|
|
8832
9342
|
var callSchema = z3.object({
|
|
8833
9343
|
at: z3.number().int().nonnegative(),
|
|
@@ -8857,7 +9367,7 @@ async function removeIfPresent5(path) {
|
|
|
8857
9367
|
}
|
|
8858
9368
|
}
|
|
8859
9369
|
async function writeAtomic4(path, value) {
|
|
8860
|
-
const temporary =
|
|
9370
|
+
const temporary = join27(join27(path, ".."), `.${basename14(path)}.${randomUUID6()}.tmp`);
|
|
8861
9371
|
try {
|
|
8862
9372
|
await writeFile4(temporary, JSON.stringify(value), { encoding: "utf8", mode: 384, flag: "wx" });
|
|
8863
9373
|
await rename4(temporary, path);
|
|
@@ -8871,7 +9381,7 @@ var UsageLedger = class {
|
|
|
8871
9381
|
}) {
|
|
8872
9382
|
this.root = root;
|
|
8873
9383
|
this.warn = warn;
|
|
8874
|
-
this.file =
|
|
9384
|
+
this.file = join27(root, "ledger.json");
|
|
8875
9385
|
}
|
|
8876
9386
|
root;
|
|
8877
9387
|
warn;
|
|
@@ -9420,7 +9930,8 @@ var skillCatalogEntrySchema = z4.strictObject({
|
|
|
9420
9930
|
updateCheckFailed: z4.boolean()
|
|
9421
9931
|
});
|
|
9422
9932
|
var listInstructionsSkillsRequestSchema = z4.strictObject({
|
|
9423
|
-
sessionId: sessionIdSchema3
|
|
9933
|
+
sessionId: sessionIdSchema3,
|
|
9934
|
+
checkUpdates: z4.boolean().optional()
|
|
9424
9935
|
});
|
|
9425
9936
|
var instructionsSkillsSnapshotSchema = z4.strictObject({
|
|
9426
9937
|
sessionId: sessionIdSchema3,
|
|
@@ -9471,7 +9982,7 @@ var createWorkspaceSkillResultCodec = codec(
|
|
|
9471
9982
|
"dsh-agent-enhancer#CreateWorkspaceSkillResult",
|
|
9472
9983
|
createWorkspaceSkillResultSchema
|
|
9473
9984
|
);
|
|
9474
|
-
var skillInstallTargetSchema = z4.enum(["user", "project"]);
|
|
9985
|
+
var skillInstallTargetSchema = z4.enum(["user", "user-dsh", "project", "project-dsh"]);
|
|
9475
9986
|
var skillInstallModeSchema = z4.enum(["link", "copy"]);
|
|
9476
9987
|
var installedSkillRefSchema = z4.strictObject({
|
|
9477
9988
|
name: z4.string().min(1),
|
|
@@ -9486,6 +9997,7 @@ var installSkillFromGitRequestSchema = z4.strictObject({
|
|
|
9486
9997
|
});
|
|
9487
9998
|
var installSkillFromGitResultSchema = z4.strictObject({
|
|
9488
9999
|
installed: z4.array(installedSkillRefSchema),
|
|
10000
|
+
skippedBusy: z4.array(z4.string().min(1)).default([]),
|
|
9489
10001
|
snapshot: instructionsSkillsSnapshotSchema
|
|
9490
10002
|
});
|
|
9491
10003
|
var installSkillFromZipRequestSchema = z4.strictObject({
|
|
@@ -9528,6 +10040,17 @@ var readSkillDocumentResultSchema = z4.strictObject({
|
|
|
9528
10040
|
text: z4.string(),
|
|
9529
10041
|
bytes: z4.number().int().nonnegative()
|
|
9530
10042
|
});
|
|
10043
|
+
var getSkillInstallProgressRequestSchema = z4.strictObject({
|
|
10044
|
+
sessionId: sessionIdSchema3
|
|
10045
|
+
});
|
|
10046
|
+
var getSkillInstallProgressResultSchema = z4.strictObject({
|
|
10047
|
+
sessionId: z4.string(),
|
|
10048
|
+
stage: z4.enum(SKILL_INSTALL_STAGES),
|
|
10049
|
+
detail: z4.string().nullable(),
|
|
10050
|
+
bytesReceived: z4.number().nonnegative().nullable(),
|
|
10051
|
+
bytesTotal: z4.number().positive().nullable(),
|
|
10052
|
+
startedAt: z4.number().nonnegative().nullable()
|
|
10053
|
+
});
|
|
9531
10054
|
var installSkillFromGitRequestCodec = codec(
|
|
9532
10055
|
"dsh-agent-enhancer#InstallSkillFromGitRequest",
|
|
9533
10056
|
installSkillFromGitRequestSchema
|
|
@@ -9568,6 +10091,14 @@ var readSkillDocumentResultCodec = codec(
|
|
|
9568
10091
|
"dsh-agent-enhancer#ReadSkillDocumentResult",
|
|
9569
10092
|
readSkillDocumentResultSchema
|
|
9570
10093
|
);
|
|
10094
|
+
var getSkillInstallProgressRequestCodec = codec(
|
|
10095
|
+
"dsh-agent-enhancer#GetSkillInstallProgressRequest",
|
|
10096
|
+
getSkillInstallProgressRequestSchema
|
|
10097
|
+
);
|
|
10098
|
+
var getSkillInstallProgressResultCodec = codec(
|
|
10099
|
+
"dsh-agent-enhancer#GetSkillInstallProgressResult",
|
|
10100
|
+
getSkillInstallProgressResultSchema
|
|
10101
|
+
);
|
|
9571
10102
|
var mcpInstallChannelSchema = z4.enum(["manual", "npx", "github", "mcpJson"]);
|
|
9572
10103
|
var mcpStdioTransportSchema = z4.strictObject({
|
|
9573
10104
|
transport: z4.literal("stdio"),
|
|
@@ -10057,6 +10588,19 @@ var remoteInfo = createTypertRemoteInfo({
|
|
|
10057
10588
|
cancellation: { parameter: "signal" },
|
|
10058
10589
|
result: readSkillDocumentResultCodec
|
|
10059
10590
|
},
|
|
10591
|
+
"agentEnhancer/getSkillInstallProgress": {
|
|
10592
|
+
service: "agentEnhancer",
|
|
10593
|
+
implementation: "getSkillInstallProgress",
|
|
10594
|
+
invocation: { kind: "direct" },
|
|
10595
|
+
parameters: [{
|
|
10596
|
+
name: "request",
|
|
10597
|
+
source: "json",
|
|
10598
|
+
codec: getSkillInstallProgressRequestCodec,
|
|
10599
|
+
strictCodec: getSkillInstallProgressRequestCodec
|
|
10600
|
+
}],
|
|
10601
|
+
cancellation: { parameter: "signal" },
|
|
10602
|
+
result: getSkillInstallProgressResultCodec
|
|
10603
|
+
},
|
|
10060
10604
|
"agentEnhancer/listMcpConnectors": {
|
|
10061
10605
|
service: "agentEnhancer",
|
|
10062
10606
|
implementation: "listMcpConnectors",
|
|
@@ -10342,8 +10886,8 @@ var checkpointRemoteInfo = createTypertRemoteInfo({
|
|
|
10342
10886
|
}, z4);
|
|
10343
10887
|
|
|
10344
10888
|
// src/host/update/check.ts
|
|
10345
|
-
import { homedir as
|
|
10346
|
-
import { join as
|
|
10889
|
+
import { homedir as homedir4 } from "node:os";
|
|
10890
|
+
import { join as join29 } from "node:path";
|
|
10347
10891
|
|
|
10348
10892
|
// src/host/update/cli.ts
|
|
10349
10893
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
@@ -10370,14 +10914,14 @@ function resolveCanAutoApply(input) {
|
|
|
10370
10914
|
return input.installKind === "npm" && input.dshAvailable;
|
|
10371
10915
|
}
|
|
10372
10916
|
function waitForExit(child, timeoutMs) {
|
|
10373
|
-
return new Promise((
|
|
10917
|
+
return new Promise((resolve16) => {
|
|
10374
10918
|
let settled = false;
|
|
10375
10919
|
const chunks = [];
|
|
10376
10920
|
const finish = (ok, detail) => {
|
|
10377
10921
|
if (settled) return;
|
|
10378
10922
|
settled = true;
|
|
10379
10923
|
clearTimeout(timer);
|
|
10380
|
-
|
|
10924
|
+
resolve16({ ok, detail });
|
|
10381
10925
|
};
|
|
10382
10926
|
const timer = setTimeout(() => {
|
|
10383
10927
|
child.kill();
|
|
@@ -10413,12 +10957,12 @@ async function runPluginAdd(latest, spawnFn = defaultSpawn) {
|
|
|
10413
10957
|
}
|
|
10414
10958
|
|
|
10415
10959
|
// src/host/update/install-kind.ts
|
|
10416
|
-
import { lstatSync as
|
|
10417
|
-
import { join as
|
|
10960
|
+
import { lstatSync as lstatSync5 } from "node:fs";
|
|
10961
|
+
import { join as join28 } from "node:path";
|
|
10418
10962
|
function detectInstallKind(profileDir) {
|
|
10419
|
-
const pkgPath =
|
|
10963
|
+
const pkgPath = join28(profileDir, "node_modules", PACKAGE_NAME);
|
|
10420
10964
|
try {
|
|
10421
|
-
const stat =
|
|
10965
|
+
const stat = lstatSync5(pkgPath);
|
|
10422
10966
|
if (stat.isSymbolicLink()) return "link";
|
|
10423
10967
|
if (stat.isDirectory()) return "npm";
|
|
10424
10968
|
return "unknown";
|
|
@@ -10546,9 +11090,9 @@ function isNewerVersion(latest, current) {
|
|
|
10546
11090
|
}
|
|
10547
11091
|
|
|
10548
11092
|
// src/host/update/check.ts
|
|
10549
|
-
function resolveDesktopProfileDir(env = process.env, home =
|
|
10550
|
-
const dshHome2 = env.DSH_HOME ??
|
|
10551
|
-
return
|
|
11093
|
+
function resolveDesktopProfileDir(env = process.env, home = homedir4()) {
|
|
11094
|
+
const dshHome2 = env.DSH_HOME ?? join29(home, ".dsh");
|
|
11095
|
+
return join29(dshHome2, "profiles", "desktop");
|
|
10552
11096
|
}
|
|
10553
11097
|
async function checkPluginUpdate(deps) {
|
|
10554
11098
|
const latest = await deps.fetchLatest();
|
|
@@ -10680,7 +11224,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
10680
11224
|
};
|
|
10681
11225
|
}
|
|
10682
11226
|
}, sessionCleanup = new SessionCleanupRegistry(), extraFolders = createExtraFoldersStore(
|
|
10683
|
-
|
|
11227
|
+
join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME, "extra-folders")
|
|
10684
11228
|
), softPause = new SoftPauseGate(), softPauseEnabled = () => true, installLedgerRoot = void 0, mcpHost = null) {
|
|
10685
11229
|
super(ctx, "agentEnhancer");
|
|
10686
11230
|
this.models = models;
|
|
@@ -11003,6 +11547,12 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
11003
11547
|
throw instructionsSkillsRemoteError(error);
|
|
11004
11548
|
}
|
|
11005
11549
|
}
|
|
11550
|
+
/** Poll GitHub skill install/update stage while installSkillFromGit / updateSkillFromGit runs. */
|
|
11551
|
+
async getSkillInstallProgress(request, signal) {
|
|
11552
|
+
this.assertOwner();
|
|
11553
|
+
signal.throwIfAborted();
|
|
11554
|
+
return getSkillInstallProgressSnapshot(String(request.sessionId));
|
|
11555
|
+
}
|
|
11006
11556
|
/** Remove a skill from a managed install root (user/project skills). */
|
|
11007
11557
|
async uninstallSkill(request, signal) {
|
|
11008
11558
|
this.assertOwner();
|
|
@@ -11182,16 +11732,16 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
11182
11732
|
}
|
|
11183
11733
|
};
|
|
11184
11734
|
function resolveCheckpointRoot(dshHome2) {
|
|
11185
|
-
const base =
|
|
11186
|
-
const nextPkg =
|
|
11187
|
-
const next =
|
|
11188
|
-
const prev =
|
|
11189
|
-
if (!
|
|
11735
|
+
const base = join30(dshHome2, "profiles", "desktop", "plugin-data");
|
|
11736
|
+
const nextPkg = join30(base, PACKAGE_NAME);
|
|
11737
|
+
const next = join30(nextPkg, "checkpoint");
|
|
11738
|
+
const prev = join30(base, LEGACY_PACKAGE_NAME, "checkpoint");
|
|
11739
|
+
if (!existsSync16(next) && existsSync16(prev)) {
|
|
11190
11740
|
mkdirSync9(nextPkg, { recursive: true });
|
|
11191
|
-
|
|
11192
|
-
const prevPkg =
|
|
11741
|
+
renameSync8(prev, next);
|
|
11742
|
+
const prevPkg = join30(base, LEGACY_PACKAGE_NAME);
|
|
11193
11743
|
try {
|
|
11194
|
-
if (
|
|
11744
|
+
if (existsSync16(prevPkg) && readdirSync7(prevPkg).length === 0) rmdirSync(prevPkg);
|
|
11195
11745
|
} catch {
|
|
11196
11746
|
}
|
|
11197
11747
|
}
|
|
@@ -11289,9 +11839,9 @@ function apply(ctx, config) {
|
|
|
11289
11839
|
const settings = () => readSettings(config);
|
|
11290
11840
|
const models = new AuxiliaryModels(ctx, settings);
|
|
11291
11841
|
installAutoSessionRoute(ctx, { settings });
|
|
11292
|
-
const storageRoot = resolveCheckpointRoot(process.env.DSH_HOME ??
|
|
11293
|
-
const pluginDataPackageRoot =
|
|
11294
|
-
const usage = new UsageLedger(
|
|
11842
|
+
const storageRoot = resolveCheckpointRoot(process.env.DSH_HOME ?? join30(homedir5(), ".dsh"));
|
|
11843
|
+
const pluginDataPackageRoot = join30(storageRoot, "..");
|
|
11844
|
+
const usage = new UsageLedger(join30(storageRoot, "..", "usage"), (message) => {
|
|
11295
11845
|
ctx.logger.warn(message);
|
|
11296
11846
|
});
|
|
11297
11847
|
const balancesFacade = (() => {
|
|
@@ -11321,12 +11871,12 @@ function apply(ctx, config) {
|
|
|
11321
11871
|
})();
|
|
11322
11872
|
installUsageObserver(ctx, usage);
|
|
11323
11873
|
const store = new CheckpointStore(storageRoot);
|
|
11324
|
-
const cutStore = new SessionCutStore(
|
|
11874
|
+
const cutStore = new SessionCutStore(join30(storageRoot, "cuts"));
|
|
11325
11875
|
const cutCache = /* @__PURE__ */ new Map();
|
|
11326
11876
|
const sessionCleanup = new SessionCleanupRegistry();
|
|
11327
11877
|
sessionCleanup.register(createCheckpointCleaner({ store, cutStore, storageRoot }));
|
|
11328
|
-
sessionCleanup.register(createContextExcludeCleaner(
|
|
11329
|
-
const extraFoldersStore = createExtraFoldersStore(
|
|
11878
|
+
sessionCleanup.register(createContextExcludeCleaner(join30(storageRoot, "..")));
|
|
11879
|
+
const extraFoldersStore = createExtraFoldersStore(join30(storageRoot, "..", "extra-folders"));
|
|
11330
11880
|
const softPauseGate = new SoftPauseGate();
|
|
11331
11881
|
const mcpStore = createMcpConnectorsStore(mcpConnectorsRoot(pluginDataPackageRoot));
|
|
11332
11882
|
const mcpRuntime = new McpConnectorRuntime(ctx, mcpStore);
|